OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/apps/chrome_shell_window_delegate.h" |
| 6 |
| 7 #include "base/stringprintf.h" |
| 8 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 9 #include "chrome/browser/file_select_helper.h" |
| 10 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 11 #include "chrome/browser/platform_util.h" |
| 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_dialogs.h" |
| 14 #include "chrome/browser/ui/browser_finder.h" |
| 15 #include "chrome/browser/ui/browser_tabstrip.h" |
| 16 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/common/render_messages.h" |
| 18 #include "content/public/browser/render_view_host.h" |
| 19 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/browser/web_contents_view.h" |
| 21 |
| 22 #if defined(USE_ASH) |
| 23 #include "ash/launcher/launcher_types.h" |
| 24 #endif |
| 25 |
| 26 namespace chrome { |
| 27 |
| 28 namespace { |
| 29 |
| 30 static bool disable_external_open_for_testing_ = false; |
| 31 |
| 32 class ShellWindowLinkDelegate : public content::WebContentsDelegate { |
| 33 private: |
| 34 virtual content::WebContents* OpenURLFromTab( |
| 35 content::WebContents* source, |
| 36 const content::OpenURLParams& params) OVERRIDE; |
| 37 }; |
| 38 |
| 39 content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab( |
| 40 content::WebContents* source, |
| 41 const content::OpenURLParams& params) { |
| 42 platform_util::OpenExternal(params.url); |
| 43 delete source; |
| 44 return NULL; |
| 45 } |
| 46 |
| 47 } // namespace |
| 48 |
| 49 ChromeShellWindowDelegate::~ChromeShellWindowDelegate() {} |
| 50 |
| 51 void ChromeShellWindowDelegate::DisableExternalOpenForTesting() { |
| 52 disable_external_open_for_testing_ = true; |
| 53 } |
| 54 |
| 55 void ChromeShellWindowDelegate::InitWebContents( |
| 56 content::WebContents* web_contents) { |
| 57 FaviconTabHelper::CreateForWebContents(web_contents); |
| 58 } |
| 59 |
| 60 content::WebContents* ChromeShellWindowDelegate::OpenURLFromTab( |
| 61 Profile* profile, |
| 62 content::WebContents* source, |
| 63 const content::OpenURLParams& params) { |
| 64 // Force all links to open in a new tab, even if they were trying to open a |
| 65 // window. |
| 66 chrome::NavigateParams new_tab_params( |
| 67 static_cast<Browser*>(NULL), params.url, params.transition); |
| 68 new_tab_params.disposition = params.disposition == NEW_BACKGROUND_TAB ? |
| 69 params.disposition : NEW_FOREGROUND_TAB; |
| 70 new_tab_params.initiating_profile = profile; |
| 71 chrome::Navigate(&new_tab_params); |
| 72 |
| 73 return new_tab_params.target_contents; |
| 74 } |
| 75 |
| 76 void ChromeShellWindowDelegate::AddNewContents( |
| 77 Profile* profile, |
| 78 content::WebContents* new_contents, |
| 79 WindowOpenDisposition disposition, |
| 80 const gfx::Rect& initial_pos, |
| 81 bool user_gesture, |
| 82 bool* was_blocked) { |
| 83 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) |
| 84 if (disable_external_open_for_testing_) { |
| 85 Browser* browser = |
| 86 chrome::FindOrCreateTabbedBrowser(profile, chrome::GetActiveDesktop()); |
| 87 // Force all links to open in a new tab, even if they were trying to open a |
| 88 // new window. |
| 89 disposition = |
| 90 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
| 91 chrome::AddWebContents(browser, NULL, new_contents, disposition, |
| 92 initial_pos, user_gesture, was_blocked); |
| 93 } else { |
| 94 new_contents->SetDelegate(new ShellWindowLinkDelegate()); |
| 95 } |
| 96 #else |
| 97 Browser* browser = |
| 98 chrome::FindOrCreateTabbedBrowser(profile, chrome::GetActiveDesktop()); |
| 99 // Force all links to open in a new tab, even if they were trying to open a |
| 100 // new window. |
| 101 disposition = |
| 102 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
| 103 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, |
| 104 user_gesture, was_blocked); |
| 105 #endif |
| 106 } |
| 107 |
| 108 content::ColorChooser* ChromeShellWindowDelegate::ShowColorChooser( |
| 109 content::WebContents* web_contents, |
| 110 SkColor initial_color) { |
| 111 return chrome::ShowColorChooser(web_contents, initial_color); |
| 112 } |
| 113 |
| 114 void ChromeShellWindowDelegate::RunFileChooser( |
| 115 content::WebContents* tab, |
| 116 const content::FileChooserParams& params) { |
| 117 FileSelectHelper::RunFileChooser(tab, params); |
| 118 } |
| 119 |
| 120 void ChromeShellWindowDelegate::RequestMediaAccessPermission( |
| 121 content::WebContents* web_contents, |
| 122 const content::MediaStreamRequest& request, |
| 123 const content::MediaResponseCallback& callback, |
| 124 const extensions::Extension* extension) { |
| 125 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( |
| 126 web_contents, request, callback, extension); |
| 127 } |
| 128 |
| 129 int ChromeShellWindowDelegate::PreferredIconSize() { |
| 130 #if defined(USE_ASH) |
| 131 return ash::kLauncherPreferredSize; |
| 132 #else |
| 133 return extension_misc::EXTENSION_ICON_SMALL; |
| 134 #endif |
| 135 } |
| 136 |
| 137 void ChromeShellWindowDelegate::SetWebContentsBlocked( |
| 138 content::WebContents* web_contents, |
| 139 bool blocked) { |
| 140 // RenderViewHost may be NULL during shutdown. |
| 141 content::RenderViewHost* host = web_contents->GetRenderViewHost(); |
| 142 if (host) { |
| 143 host->Send(new ChromeViewMsg_SetVisuallyDeemphasized( |
| 144 host->GetRoutingID(), blocked)); |
| 145 } |
| 146 } |
| 147 |
| 148 bool ChromeShellWindowDelegate::IsWebContentsVisible( |
| 149 content::WebContents* web_contents) { |
| 150 return platform_util::IsVisible(web_contents->GetView()->GetNativeView()); |
| 151 } |
| 152 |
| 153 } // namespace chrome |
OLD | NEW |