| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 iter = request->devices.find(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE); | 126 iter = request->devices.find(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE); |
| 124 if (iter != request->devices.end() && | 127 if (iter != request->devices.end() && |
| 125 extension()->HasAPIPermission(ExtensionAPIPermission::kVideoCapture) && | 128 extension()->HasAPIPermission(ExtensionAPIPermission::kVideoCapture) && |
| 126 !iter->second.empty()) { | 129 !iter->second.empty()) { |
| 127 devices.push_back(iter->second[0]); | 130 devices.push_back(iter->second[0]); |
| 128 } | 131 } |
| 129 | 132 |
| 130 callback.Run(devices); | 133 callback.Run(devices); |
| 131 } | 134 } |
| 132 | 135 |
| 136 WebContents* ShellWindow::OpenURLFromTab(WebContents* source, |
| 137 const content::OpenURLParams& params) { |
| 138 DCHECK(source == web_contents_); |
| 139 |
| 140 if (params.url.host() == extension_->id()) { |
| 141 AddMessageToDevToolsConsole( |
| 142 content::CONSOLE_MESSAGE_LEVEL_ERROR, |
| 143 base::StringPrintf( |
| 144 "Can't navigate to \"%s\"; apps do not support navigation.", |
| 145 params.url.spec().c_str())); |
| 146 return NULL; |
| 147 } |
| 148 |
| 149 // Don't allow the current tab to be navigated. It would be nice to map all |
| 150 // anchor tags (even those without target="_blank") to new tabs, but right |
| 151 // now we can't distinguish between those and <meta> refreshes, which we |
| 152 // don't want to allow. |
| 153 // TOOD(mihaip): Can we check for user gestures instead? |
| 154 WindowOpenDisposition disposition = params.disposition; |
| 155 if (disposition == CURRENT_TAB) { |
| 156 AddMessageToDevToolsConsole( |
| 157 content::CONSOLE_MESSAGE_LEVEL_ERROR, |
| 158 base::StringPrintf( |
| 159 "Can't open same-window link to \"%s\"; try target=\"_blank\".", |
| 160 params.url.spec().c_str())); |
| 161 return NULL; |
| 162 } |
| 163 |
| 164 // These dispositions aren't really navigations. |
| 165 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || |
| 166 disposition == IGNORE_ACTION) { |
| 167 return NULL; |
| 168 } |
| 169 |
| 170 // Force all links to open in a new tab, even if they were trying to open a |
| 171 // window. |
| 172 content::OpenURLParams new_tab_params = params; |
| 173 new_tab_params.disposition = |
| 174 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
| 175 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); |
| 176 WebContents* new_tab = browser->OpenURL(new_tab_params); |
| 177 browser->window()->Show(); |
| 178 return new_tab; |
| 179 } |
| 180 |
| 181 void ShellWindow::AddNewContents(WebContents* source, |
| 182 WebContents* new_contents, |
| 183 WindowOpenDisposition disposition, |
| 184 const gfx::Rect& initial_pos, |
| 185 bool user_gesture) { |
| 186 DCHECK(source == web_contents_); |
| 187 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == |
| 188 profile_); |
| 189 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); |
| 190 // Force all links to open in a new tab, even if they were trying to open a |
| 191 // new window. |
| 192 disposition = |
| 193 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
| 194 browser->AddWebContents( |
| 195 new_contents, disposition, initial_pos, user_gesture); |
| 196 } |
| 197 |
| 133 void ShellWindow::OnNativeClose() { | 198 void ShellWindow::OnNativeClose() { |
| 134 ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); | 199 ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); |
| 135 delete this; | 200 delete this; |
| 136 } | 201 } |
| 137 | 202 |
| 138 string16 ShellWindow::GetTitle() const { | 203 string16 ShellWindow::GetTitle() const { |
| 139 // WebContents::GetTitle() will return the page's URL if there's no <title> | 204 // WebContents::GetTitle() will return the page's URL if there's no <title> |
| 140 // specified. However, we'd prefer to show the name of the extension in that | 205 // specified. However, we'd prefer to show the name of the extension in that |
| 141 // case, so we directly inspect the NavigationEntry's title. | 206 // case, so we directly inspect the NavigationEntry's title. |
| 142 if (!web_contents()->GetController().GetActiveEntry() || | 207 if (!web_contents()->GetController().GetActiveEntry() || |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 } | 295 } |
| 231 | 296 |
| 232 ExtensionWindowController* ShellWindow::GetExtensionWindowController() const { | 297 ExtensionWindowController* ShellWindow::GetExtensionWindowController() const { |
| 233 return NULL; | 298 return NULL; |
| 234 } | 299 } |
| 235 | 300 |
| 236 void ShellWindow::OnRequest(const ExtensionHostMsg_Request_Params& params) { | 301 void ShellWindow::OnRequest(const ExtensionHostMsg_Request_Params& params) { |
| 237 extension_function_dispatcher_.Dispatch(params, | 302 extension_function_dispatcher_.Dispatch(params, |
| 238 web_contents_->GetRenderViewHost()); | 303 web_contents_->GetRenderViewHost()); |
| 239 } | 304 } |
| 305 |
| 306 void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level, |
| 307 const std::string& message) { |
| 308 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
| 309 rvh->Send(new ExtensionMsg_AddMessageToConsole( |
| 310 rvh->GetRoutingID(), level, message)); |
| 311 } |
| OLD | NEW |