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/strings/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 bool disable_external_open_for_testing_ = false; |
| 31 |
| 32 class ShellWindowLinkDelegate : public content::WebContentsDelegate { |
| 33 public: |
| 34 ShellWindowLinkDelegate(); |
| 35 |
| 36 private: |
| 37 virtual content::WebContents* OpenURLFromTab( |
| 38 content::WebContents* source, |
| 39 const content::OpenURLParams& params) OVERRIDE; |
| 40 |
| 41 DISALLOW_COPY_AND_ASSIGN(ShellWindowLinkDelegate); |
| 42 }; |
| 43 |
| 44 ShellWindowLinkDelegate::ShellWindowLinkDelegate() {} |
| 45 |
| 46 // TODO(rockot): Add a test that exercises this code. See |
| 47 // http://crbug.com/254260. |
| 48 content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab( |
| 49 content::WebContents* source, |
| 50 const content::OpenURLParams& params) { |
| 51 platform_util::OpenExternal(params.url); |
| 52 delete source; |
| 53 return NULL; |
| 54 } |
| 55 |
| 56 } // namespace |
| 57 |
| 58 ChromeShellWindowDelegate::ChromeShellWindowDelegate() {} |
| 59 |
| 60 ChromeShellWindowDelegate::~ChromeShellWindowDelegate() {} |
| 61 |
| 62 void ChromeShellWindowDelegate::DisableExternalOpenForTesting() { |
| 63 disable_external_open_for_testing_ = true; |
| 64 } |
| 65 |
| 66 void ChromeShellWindowDelegate::InitWebContents( |
| 67 content::WebContents* web_contents) { |
| 68 FaviconTabHelper::CreateForWebContents(web_contents); |
| 69 } |
| 70 |
| 71 content::WebContents* ChromeShellWindowDelegate::OpenURLFromTab( |
| 72 Profile* profile, |
| 73 content::WebContents* source, |
| 74 const content::OpenURLParams& params) { |
| 75 // Force all links to open in a new tab, even if they were trying to open a |
| 76 // window. |
| 77 chrome::NavigateParams new_tab_params( |
| 78 static_cast<Browser*>(NULL), params.url, params.transition); |
| 79 new_tab_params.disposition = params.disposition == NEW_BACKGROUND_TAB ? |
| 80 params.disposition : NEW_FOREGROUND_TAB; |
| 81 new_tab_params.initiating_profile = profile; |
| 82 chrome::Navigate(&new_tab_params); |
| 83 |
| 84 return new_tab_params.target_contents; |
| 85 } |
| 86 |
| 87 void ChromeShellWindowDelegate::AddNewContents( |
| 88 Profile* profile, |
| 89 content::WebContents* new_contents, |
| 90 WindowOpenDisposition disposition, |
| 91 const gfx::Rect& initial_pos, |
| 92 bool user_gesture, |
| 93 bool* was_blocked) { |
| 94 #if defined(OS_MACOSX) || defined(OS_WIN) || \ |
| 95 (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
| 96 if (!disable_external_open_for_testing_) { |
| 97 new_contents->SetDelegate(new ShellWindowLinkDelegate()); |
| 98 return; |
| 99 } |
| 100 #endif |
| 101 Browser* browser = |
| 102 chrome::FindOrCreateTabbedBrowser(profile, chrome::GetActiveDesktop()); |
| 103 // Force all links to open in a new tab, even if they were trying to open a |
| 104 // new window. |
| 105 disposition = |
| 106 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
| 107 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, |
| 108 user_gesture, was_blocked); |
| 109 } |
| 110 |
| 111 content::ColorChooser* ChromeShellWindowDelegate::ShowColorChooser( |
| 112 content::WebContents* web_contents, |
| 113 SkColor initial_color) { |
| 114 return chrome::ShowColorChooser(web_contents, initial_color); |
| 115 } |
| 116 |
| 117 void ChromeShellWindowDelegate::RunFileChooser( |
| 118 content::WebContents* tab, |
| 119 const content::FileChooserParams& params) { |
| 120 FileSelectHelper::RunFileChooser(tab, params); |
| 121 } |
| 122 |
| 123 void ChromeShellWindowDelegate::RequestMediaAccessPermission( |
| 124 content::WebContents* web_contents, |
| 125 const content::MediaStreamRequest& request, |
| 126 const content::MediaResponseCallback& callback, |
| 127 const extensions::Extension* extension) { |
| 128 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( |
| 129 web_contents, request, callback, extension); |
| 130 } |
| 131 |
| 132 int ChromeShellWindowDelegate::PreferredIconSize() { |
| 133 #if defined(USE_ASH) |
| 134 return ash::kLauncherPreferredSize; |
| 135 #else |
| 136 return extension_misc::EXTENSION_ICON_SMALL; |
| 137 #endif |
| 138 } |
| 139 |
| 140 void ChromeShellWindowDelegate::SetWebContentsBlocked( |
| 141 content::WebContents* web_contents, |
| 142 bool blocked) { |
| 143 // RenderViewHost may be NULL during shutdown. |
| 144 content::RenderViewHost* host = web_contents->GetRenderViewHost(); |
| 145 if (host) { |
| 146 host->Send(new ChromeViewMsg_SetVisuallyDeemphasized( |
| 147 host->GetRoutingID(), blocked)); |
| 148 } |
| 149 } |
| 150 |
| 151 bool ChromeShellWindowDelegate::IsWebContentsVisible( |
| 152 content::WebContents* web_contents) { |
| 153 return platform_util::IsVisible(web_contents->GetView()->GetNativeView()); |
| 154 } |
| 155 |
| 156 } // namespace chrome |
OLD | NEW |