| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/extensions/shell_window.h" | 5 #include "chrome/browser/ui/extensions/shell_window.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/extension_process_manager.h" | 8 #include "chrome/browser/extensions/extension_process_manager.h" |
| 9 #include "chrome/browser/extensions/shell_window_registry.h" | 9 #include "chrome/browser/extensions/shell_window_registry.h" |
| 10 #include "chrome/browser/file_select_helper.h" | 10 #include "chrome/browser/file_select_helper.h" |
| 11 #include "chrome/browser/intents/web_intents_util.h" | 11 #include "chrome/browser/intents/web_intents_util.h" |
| 12 #include "chrome/browser/lifetime/application_lifetime.h" | 12 #include "chrome/browser/lifetime/application_lifetime.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/sessions/session_id.h" | 14 #include "chrome/browser/sessions/session_id.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_finder.h" |
| 17 #include "chrome/browser/ui/browser_window.h" |
| 16 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | 18 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 18 #include "chrome/browser/view_type_utils.h" | 20 #include "chrome/browser/view_type_utils.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/extensions/extension_messages.h" | 23 #include "chrome/common/extensions/extension_messages.h" |
| 22 #include "content/public/browser/invalidate_type.h" | 24 #include "content/public/browser/invalidate_type.h" |
| 23 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
| 24 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
| 25 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/browser/notification_source.h" | 28 #include "content/public/browser/notification_source.h" |
| 27 #include "content/public/browser/notification_types.h" | 29 #include "content/public/browser/notification_types.h" |
| 28 #include "content/public/browser/render_view_host.h" | 30 #include "content/public/browser/render_view_host.h" |
| 29 #include "content/public/browser/site_instance.h" | 31 #include "content/public/browser/site_instance.h" |
| 30 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/browser/web_intents_dispatcher.h" | 33 #include "content/public/browser/web_intents_dispatcher.h" |
| 32 #include "content/public/common/renderer_preferences.h" | 34 #include "content/public/common/renderer_preferences.h" |
| 33 | 35 |
| 36 using content::ConsoleMessageLevel; |
| 34 using content::SiteInstance; | 37 using content::SiteInstance; |
| 35 using content::WebContents; | 38 using content::WebContents; |
| 36 | 39 |
| 37 namespace { | 40 namespace { |
| 38 static const int kDefaultWidth = 512; | 41 static const int kDefaultWidth = 512; |
| 39 static const int kDefaultHeight = 384; | 42 static const int kDefaultHeight = 384; |
| 40 } // namespace | 43 } // namespace |
| 41 | 44 |
| 42 ShellWindow::CreateParams::CreateParams() | 45 ShellWindow::CreateParams::CreateParams() |
| 43 : frame(ShellWindow::CreateParams::FRAME_CHROME), | 46 : frame(ShellWindow::CreateParams::FRAME_CHROME), |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 return false; | 109 return false; |
| 107 } | 110 } |
| 108 | 111 |
| 109 void ShellWindow::RequestMediaAccessPermission( | 112 void ShellWindow::RequestMediaAccessPermission( |
| 110 content::WebContents* web_contents, | 113 content::WebContents* web_contents, |
| 111 const content::MediaStreamRequest* request, | 114 const content::MediaStreamRequest* request, |
| 112 const content::MediaResponseCallback& callback) { | 115 const content::MediaResponseCallback& callback) { |
| 113 callback.Run(content::MediaStreamDevices()); | 116 callback.Run(content::MediaStreamDevices()); |
| 114 } | 117 } |
| 115 | 118 |
| 119 WebContents* ShellWindow::OpenURLFromTab(WebContents* source, |
| 120 const content::OpenURLParams& params) { |
| 121 DCHECK(source == web_contents_); |
| 122 |
| 123 if (params.url.host() == extension_->id()) { |
| 124 AddMessageToDevToolsConsole( |
| 125 content::CONSOLE_MESSAGE_LEVEL_ERROR, |
| 126 base::StringPrintf( |
| 127 "Can't navigate to \"%s\", apps do not support navigation.", |
| 128 params.url.spec().c_str())); |
| 129 return NULL; |
| 130 } |
| 131 |
| 132 // Don't allow the current tab to be navigated. It would be nice to map all |
| 133 // anchor tags (even those without target="_blank") to new tabs, but right |
| 134 // now we can't distinguish between those and <meta> refreshes, which we |
| 135 // don't want to allow. |
| 136 // TOOD(mihaip): Can we check for user gestures instead? |
| 137 WindowOpenDisposition disposition = params.disposition; |
| 138 if (disposition == CURRENT_TAB) { |
| 139 AddMessageToDevToolsConsole( |
| 140 content::CONSOLE_MESSAGE_LEVEL_ERROR, |
| 141 base::StringPrintf( |
| 142 "Can't open same-window link to \"%s\", try target=\"_blank\".", |
| 143 params.url.spec().c_str())); |
| 144 return NULL; |
| 145 } |
| 146 |
| 147 // These dispositions aren't really navigations. |
| 148 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || |
| 149 disposition == IGNORE_ACTION) { |
| 150 return NULL; |
| 151 } |
| 152 |
| 153 // Force all links to open in a new tab, even if they were trying to open a |
| 154 // window. |
| 155 content::OpenURLParams new_tab_params = params; |
| 156 new_tab_params.disposition = |
| 157 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
| 158 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); |
| 159 WebContents* new_tab = browser->OpenURL(new_tab_params); |
| 160 browser->window()->Show(); |
| 161 return new_tab; |
| 162 } |
| 163 |
| 164 void ShellWindow::AddNewContents(WebContents* source, |
| 165 WebContents* new_contents, |
| 166 WindowOpenDisposition disposition, |
| 167 const gfx::Rect& initial_pos, |
| 168 bool user_gesture) { |
| 169 DCHECK(source == web_contents_); |
| 170 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == |
| 171 profile_); |
| 172 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); |
| 173 // Force all links to open in a new tab, even if they were trying to open a |
| 174 // new window. |
| 175 disposition = |
| 176 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
| 177 browser->AddWebContents( |
| 178 new_contents, disposition, initial_pos, user_gesture); |
| 179 } |
| 180 |
| 116 void ShellWindow::OnNativeClose() { | 181 void ShellWindow::OnNativeClose() { |
| 117 ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); | 182 ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); |
| 118 delete this; | 183 delete this; |
| 119 } | 184 } |
| 120 | 185 |
| 121 string16 ShellWindow::GetTitle() const { | 186 string16 ShellWindow::GetTitle() const { |
| 122 // WebContents::GetTitle() will return the page's URL if there's no <title> | 187 // WebContents::GetTitle() will return the page's URL if there's no <title> |
| 123 // specified. However, we'd prefer to show the name of the extension in that | 188 // specified. However, we'd prefer to show the name of the extension in that |
| 124 // case, so we directly inspect the NavigationEntry's title. | 189 // case, so we directly inspect the NavigationEntry's title. |
| 125 if (!web_contents()->GetController().GetActiveEntry() || | 190 if (!web_contents()->GetController().GetActiveEntry() || |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 } | 278 } |
| 214 | 279 |
| 215 ExtensionWindowController* ShellWindow::GetExtensionWindowController() const { | 280 ExtensionWindowController* ShellWindow::GetExtensionWindowController() const { |
| 216 return NULL; | 281 return NULL; |
| 217 } | 282 } |
| 218 | 283 |
| 219 void ShellWindow::OnRequest(const ExtensionHostMsg_Request_Params& params) { | 284 void ShellWindow::OnRequest(const ExtensionHostMsg_Request_Params& params) { |
| 220 extension_function_dispatcher_.Dispatch(params, | 285 extension_function_dispatcher_.Dispatch(params, |
| 221 web_contents_->GetRenderViewHost()); | 286 web_contents_->GetRenderViewHost()); |
| 222 } | 287 } |
| 288 |
| 289 void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level, |
| 290 const std::string& message) { |
| 291 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
| 292 rvh->Send(new ExtensionMsg_AddMessageToConsole( |
| 293 rvh->GetRoutingID(), level, message)); |
| 294 } |
| OLD | NEW |