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/extensions/tab_helper.h" | 5 #include "chrome/browser/extensions/tab_helper.h" |
6 | 6 |
| 7 #include "base/logging.h" |
7 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/extensions/activity_log/activity_log.h" | 9 #include "chrome/browser/extensions/activity_log/activity_log.h" |
9 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" | 10 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" |
10 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist
ry.h" | 11 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist
ry.h" |
11 #include "chrome/browser/extensions/crx_installer.h" | 12 #include "chrome/browser/extensions/crx_installer.h" |
| 13 #include "chrome/browser/extensions/error_console/error_console.h" |
12 #include "chrome/browser/extensions/extension_action.h" | 14 #include "chrome/browser/extensions/extension_action.h" |
13 #include "chrome/browser/extensions/extension_action_manager.h" | 15 #include "chrome/browser/extensions/extension_action_manager.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/extensions/extension_system.h" | 17 #include "chrome/browser/extensions/extension_system.h" |
16 #include "chrome/browser/extensions/extension_tab_util.h" | 18 #include "chrome/browser/extensions/extension_tab_util.h" |
17 #include "chrome/browser/extensions/image_loader.h" | 19 #include "chrome/browser/extensions/image_loader.h" |
18 #include "chrome/browser/extensions/page_action_controller.h" | 20 #include "chrome/browser/extensions/page_action_controller.h" |
19 #include "chrome/browser/extensions/script_badge_controller.h" | 21 #include "chrome/browser/extensions/script_badge_controller.h" |
20 #include "chrome/browser/extensions/script_bubble_controller.h" | 22 #include "chrome/browser/extensions/script_bubble_controller.h" |
21 #include "chrome/browser/extensions/script_executor.h" | 23 #include "chrome/browser/extensions/script_executor.h" |
22 #include "chrome/browser/extensions/webstore_inline_installer.h" | 24 #include "chrome/browser/extensions/webstore_inline_installer.h" |
23 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/sessions/session_id.h" | 26 #include "chrome/browser/sessions/session_id.h" |
25 #include "chrome/browser/sessions/session_tab_helper.h" | 27 #include "chrome/browser/sessions/session_tab_helper.h" |
26 #include "chrome/browser/ui/browser_dialogs.h" | 28 #include "chrome/browser/ui/browser_dialogs.h" |
27 #include "chrome/browser/ui/web_applications/web_app_ui.h" | 29 #include "chrome/browser/ui/web_applications/web_app_ui.h" |
28 #include "chrome/browser/web_applications/web_app.h" | 30 #include "chrome/browser/web_applications/web_app.h" |
29 #include "chrome/common/extensions/extension.h" | 31 #include "chrome/common/extensions/extension.h" |
30 #include "chrome/common/extensions/extension_constants.h" | 32 #include "chrome/common/extensions/extension_constants.h" |
31 #include "chrome/common/extensions/extension_icon_set.h" | 33 #include "chrome/common/extensions/extension_icon_set.h" |
32 #include "chrome/common/extensions/extension_messages.h" | 34 #include "chrome/common/extensions/extension_messages.h" |
33 #include "chrome/common/extensions/feature_switch.h" | 35 #include "chrome/common/extensions/feature_switch.h" |
34 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 36 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
35 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 37 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
| 38 #include "chrome/common/render_messages.h" |
36 #include "content/public/browser/invalidate_type.h" | 39 #include "content/public/browser/invalidate_type.h" |
37 #include "content/public/browser/navigation_controller.h" | 40 #include "content/public/browser/navigation_controller.h" |
38 #include "content/public/browser/navigation_details.h" | 41 #include "content/public/browser/navigation_details.h" |
39 #include "content/public/browser/navigation_entry.h" | 42 #include "content/public/browser/navigation_entry.h" |
40 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
41 #include "content/public/browser/notification_source.h" | 44 #include "content/public/browser/notification_source.h" |
42 #include "content/public/browser/notification_types.h" | 45 #include "content/public/browser/notification_types.h" |
43 #include "content/public/browser/render_process_host.h" | 46 #include "content/public/browser/render_process_host.h" |
44 #include "content/public/browser/render_view_host.h" | 47 #include "content/public/browser/render_view_host.h" |
45 #include "content/public/browser/render_widget_host_view.h" | 48 #include "content/public/browser/render_widget_host_view.h" |
46 #include "content/public/browser/web_contents.h" | 49 #include "content/public/browser/web_contents.h" |
47 #include "content/public/browser/web_contents_view.h" | 50 #include "content/public/browser/web_contents_view.h" |
| 51 #include "extensions/browser/extension_error.h" |
48 #include "extensions/common/extension_resource.h" | 52 #include "extensions/common/extension_resource.h" |
| 53 #include "extensions/common/extension_urls.h" |
49 #include "ui/gfx/image/image.h" | 54 #include "ui/gfx/image/image.h" |
50 | 55 |
51 using content::NavigationController; | 56 using content::NavigationController; |
52 using content::NavigationEntry; | 57 using content::NavigationEntry; |
53 using content::RenderViewHost; | 58 using content::RenderViewHost; |
54 using content::WebContents; | 59 using content::WebContents; |
55 | 60 |
56 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::TabHelper); | 61 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::TabHelper); |
57 | 62 |
58 namespace { | 63 namespace { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 OnDidGetApplicationInfo) | 235 OnDidGetApplicationInfo) |
231 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, | 236 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, |
232 OnInlineWebstoreInstall) | 237 OnInlineWebstoreInstall) |
233 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, | 238 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, |
234 OnGetAppInstallState); | 239 OnGetAppInstallState); |
235 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 240 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
236 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, | 241 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, |
237 OnContentScriptsExecuting) | 242 OnContentScriptsExecuting) |
238 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange, | 243 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange, |
239 OnWatchedPageChange) | 244 OnWatchedPageChange) |
| 245 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DetailedConsoleMessageAdded, |
| 246 OnDetailedConsoleMessageAdded) |
240 IPC_MESSAGE_UNHANDLED(handled = false) | 247 IPC_MESSAGE_UNHANDLED(handled = false) |
241 IPC_END_MESSAGE_MAP() | 248 IPC_END_MESSAGE_MAP() |
242 return handled; | 249 return handled; |
243 } | 250 } |
244 | 251 |
245 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, | 252 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, |
246 WebContents* new_web_contents) { | 253 WebContents* new_web_contents) { |
247 // When the WebContents that this is attached to is cloned, give the new clone | 254 // When the WebContents that this is attached to is cloned, give the new clone |
248 // a TabHelper and copy state over. | 255 // a TabHelper and copy state over. |
249 CreateForWebContents(new_web_contents); | 256 CreateForWebContents(new_web_contents); |
250 TabHelper* new_helper = FromWebContents(new_web_contents); | 257 TabHelper* new_helper = FromWebContents(new_web_contents); |
251 | 258 |
252 new_helper->SetExtensionApp(extension_app()); | 259 new_helper->SetExtensionApp(extension_app()); |
253 new_helper->extension_app_icon_ = extension_app_icon_; | 260 new_helper->extension_app_icon_ = extension_app_icon_; |
254 } | 261 } |
255 | 262 |
256 | |
257 void TabHelper::OnDidGetApplicationInfo(int32 page_id, | 263 void TabHelper::OnDidGetApplicationInfo(int32 page_id, |
258 const WebApplicationInfo& info) { | 264 const WebApplicationInfo& info) { |
259 // Android does not implement BrowserWindow. | 265 // Android does not implement BrowserWindow. |
260 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 266 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
261 web_app_info_ = info; | 267 web_app_info_ = info; |
262 | 268 |
263 NavigationEntry* entry = | 269 NavigationEntry* entry = |
264 web_contents()->GetController().GetLastCommittedEntry(); | 270 web_contents()->GetController().GetLastCommittedEntry(); |
265 if (!entry || (entry->GetPageID() != page_id)) | 271 if (!entry || (entry->GetPageID() != page_id)) |
266 return; | 272 return; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 const std::vector<std::string>& css_selectors) { | 349 const std::vector<std::string>& css_selectors) { |
344 #if defined(ENABLE_EXTENSIONS) | 350 #if defined(ENABLE_EXTENSIONS) |
345 if (ExtensionSystem::Get(profile_)->extension_service() && | 351 if (ExtensionSystem::Get(profile_)->extension_service() && |
346 RulesRegistryService::Get(profile_)) { | 352 RulesRegistryService::Get(profile_)) { |
347 RulesRegistryService::Get(profile_)->content_rules_registry()->Apply( | 353 RulesRegistryService::Get(profile_)->content_rules_registry()->Apply( |
348 web_contents(), css_selectors); | 354 web_contents(), css_selectors); |
349 } | 355 } |
350 #endif // defined(ENABLE_EXTENSIONS) | 356 #endif // defined(ENABLE_EXTENSIONS) |
351 } | 357 } |
352 | 358 |
| 359 void TabHelper::OnDetailedConsoleMessageAdded( |
| 360 const base::string16& message, |
| 361 const base::string16& source, |
| 362 const StackTrace& stack_trace, |
| 363 int32 severity_level) { |
| 364 if (IsSourceFromAnExtension(source)) { |
| 365 ErrorConsole::Get(profile_)->ReportError( |
| 366 scoped_ptr<ExtensionError>(new RuntimeError( |
| 367 profile_->IsOffTheRecord(), |
| 368 source, |
| 369 message, |
| 370 stack_trace, |
| 371 web_contents() ? |
| 372 web_contents()->GetLastCommittedURL() : GURL::EmptyGURL(), |
| 373 static_cast<logging::LogSeverity>(severity_level)))); |
| 374 } |
| 375 } |
| 376 |
353 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) { | 377 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) { |
354 if (extension_app_id.empty()) | 378 if (extension_app_id.empty()) |
355 return NULL; | 379 return NULL; |
356 | 380 |
357 Profile* profile = | 381 Profile* profile = |
358 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 382 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
359 ExtensionService* extension_service = profile->GetExtensionService(); | 383 ExtensionService* extension_service = profile->GetExtensionService(); |
360 if (!extension_service || !extension_service->is_ready()) | 384 if (!extension_service || !extension_service->is_ready()) |
361 return NULL; | 385 return NULL; |
362 | 386 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 } | 477 } |
454 } | 478 } |
455 | 479 |
456 void TabHelper::SetTabId(RenderViewHost* render_view_host) { | 480 void TabHelper::SetTabId(RenderViewHost* render_view_host) { |
457 render_view_host->Send( | 481 render_view_host->Send( |
458 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), | 482 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), |
459 SessionID::IdForTab(web_contents()))); | 483 SessionID::IdForTab(web_contents()))); |
460 } | 484 } |
461 | 485 |
462 } // namespace extensions | 486 } // namespace extensions |
OLD | NEW |