| 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/extension_tab_helper.h" | 5 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/extensions/page_action_controller.h" | 8 #include "chrome/browser/extensions/page_action_controller.h" |
| 9 #include "chrome/browser/extensions/script_badge_controller.h" | 9 #include "chrome/browser/extensions/script_badge_controller.h" |
| 10 #include "chrome/browser/extensions/script_executor_impl.h" | 10 #include "chrome/browser/extensions/script_executor_impl.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/common/extensions/extension_switch_utils.h" | 23 #include "chrome/common/extensions/extension_switch_utils.h" |
| 24 #include "content/public/browser/invalidate_type.h" | 24 #include "content/public/browser/invalidate_type.h" |
| 25 #include "content/public/browser/navigation_details.h" | 25 #include "content/public/browser/navigation_details.h" |
| 26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
| 28 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
| 29 #include "content/public/browser/render_widget_host_view.h" | 29 #include "content/public/browser/render_widget_host_view.h" |
| 30 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 31 #include "ui/gfx/image/image.h" | 31 #include "ui/gfx/image/image.h" |
| 32 | 32 |
| 33 using content::RenderViewHost; |
| 33 using content::WebContents; | 34 using content::WebContents; |
| 34 using extensions::Extension; | 35 using extensions::Extension; |
| 36 using extensions::PageActionController; |
| 35 using extensions::ScriptBadgeController; | 37 using extensions::ScriptBadgeController; |
| 36 using extensions::ScriptExecutorImpl; | 38 using extensions::ScriptExecutorImpl; |
| 37 using extensions::PageActionController; | |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 const char kPermissionError[] = "permission_error"; | 42 const char kPermissionError[] = "permission_error"; |
| 42 | 43 |
| 43 } // namespace | 44 } // namespace |
| 44 | 45 |
| 45 ExtensionTabHelper::ExtensionTabHelper(TabContents* tab_contents) | 46 ExtensionTabHelper::ExtensionTabHelper(TabContents* tab_contents) |
| 46 : content::WebContentsObserver(tab_contents->web_contents()), | 47 : content::WebContentsObserver(tab_contents->web_contents()), |
| 47 delegate_(NULL), | 48 delegate_(NULL), |
| 48 extension_app_(NULL), | 49 extension_app_(NULL), |
| 49 ALLOW_THIS_IN_INITIALIZER_LIST( | 50 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 50 extension_function_dispatcher_(tab_contents->profile(), this)), | 51 extension_function_dispatcher_(tab_contents->profile(), this)), |
| 51 tab_contents_(tab_contents) { | 52 tab_contents_(tab_contents), |
| 53 active_tab_permission_manager_(tab_contents) { |
| 52 if (extensions::switch_utils::IsActionBoxEnabled()) { | 54 if (extensions::switch_utils::IsActionBoxEnabled()) { |
| 53 script_badge_controller_ = new ScriptBadgeController(tab_contents); | 55 script_badge_controller_ = new ScriptBadgeController(tab_contents); |
| 54 } else { | 56 } else { |
| 55 script_executor_.reset( | 57 script_executor_.reset( |
| 56 new ScriptExecutorImpl(tab_contents->web_contents())); | 58 new ScriptExecutorImpl(tab_contents->web_contents())); |
| 57 location_bar_controller_.reset(new PageActionController(tab_contents)); | 59 location_bar_controller_.reset(new PageActionController(tab_contents)); |
| 58 } | 60 } |
| 59 } | 61 } |
| 60 | 62 |
| 61 ExtensionTabHelper::~ExtensionTabHelper() { | 63 ExtensionTabHelper::~ExtensionTabHelper() { |
| 62 } | 64 } |
| 63 | 65 |
| 64 void ExtensionTabHelper::CopyStateFrom(const ExtensionTabHelper& source) { | 66 void ExtensionTabHelper::CopyStateFrom(const ExtensionTabHelper& source) { |
| 65 SetExtensionApp(source.extension_app()); | 67 SetExtensionApp(source.extension_app()); |
| 66 extension_app_icon_ = source.extension_app_icon_; | 68 extension_app_icon_ = source.extension_app_icon_; |
| 67 } | 69 } |
| 68 | 70 |
| 69 void ExtensionTabHelper::PageActionStateChanged() { | 71 void ExtensionTabHelper::PageActionStateChanged() { |
| 70 web_contents()->NotifyNavigationStateChanged( | 72 web_contents()->NotifyNavigationStateChanged( |
| 71 content::INVALIDATE_TYPE_PAGE_ACTIONS); | 73 content::INVALIDATE_TYPE_PAGE_ACTIONS); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void ExtensionTabHelper::GetApplicationInfo(int32 page_id) { | 76 void ExtensionTabHelper::GetApplicationInfo(int32 page_id) { |
| 75 Send(new ExtensionMsg_GetApplicationInfo(routing_id(), page_id)); | 77 Send(new ExtensionMsg_GetApplicationInfo(routing_id(), page_id)); |
| 76 } | 78 } |
| 77 | 79 |
| 80 int ExtensionTabHelper::tab_id() const { |
| 81 return tab_contents_->restore_tab_helper()->session_id().id(); |
| 82 } |
| 83 |
| 84 int ExtensionTabHelper::window_id() const { |
| 85 return tab_contents_->restore_tab_helper()->window_id().id(); |
| 86 } |
| 87 |
| 78 void ExtensionTabHelper::SetExtensionApp(const Extension* extension) { | 88 void ExtensionTabHelper::SetExtensionApp(const Extension* extension) { |
| 79 DCHECK(!extension || extension->GetFullLaunchURL().is_valid()); | 89 DCHECK(!extension || extension->GetFullLaunchURL().is_valid()); |
| 80 extension_app_ = extension; | 90 extension_app_ = extension; |
| 81 | 91 |
| 82 UpdateExtensionAppIcon(extension_app_); | 92 UpdateExtensionAppIcon(extension_app_); |
| 83 | 93 |
| 84 content::NotificationService::current()->Notify( | 94 content::NotificationService::current()->Notify( |
| 85 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, | 95 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
| 86 content::Source<ExtensionTabHelper>(this), | 96 content::Source<ExtensionTabHelper>(this), |
| 87 content::NotificationService::NoDetails()); | 97 content::NotificationService::NoDetails()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 114 return script_executor_.get(); | 124 return script_executor_.get(); |
| 115 } | 125 } |
| 116 | 126 |
| 117 extensions::LocationBarController* | 127 extensions::LocationBarController* |
| 118 ExtensionTabHelper::location_bar_controller() { | 128 ExtensionTabHelper::location_bar_controller() { |
| 119 if (script_badge_controller_.get()) | 129 if (script_badge_controller_.get()) |
| 120 return script_badge_controller_.get(); | 130 return script_badge_controller_.get(); |
| 121 return location_bar_controller_.get(); | 131 return location_bar_controller_.get(); |
| 122 } | 132 } |
| 123 | 133 |
| 134 void ExtensionTabHelper::RenderViewCreated(RenderViewHost* render_view_host) { |
| 135 render_view_host->Send( |
| 136 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), tab_id())); |
| 137 } |
| 138 |
| 124 void ExtensionTabHelper::DidNavigateMainFrame( | 139 void ExtensionTabHelper::DidNavigateMainFrame( |
| 125 const content::LoadCommittedDetails& details, | 140 const content::LoadCommittedDetails& details, |
| 126 const content::FrameNavigateParams& params) { | 141 const content::FrameNavigateParams& params) { |
| 127 if (details.is_in_page) | 142 if (details.is_in_page) |
| 128 return; | 143 return; |
| 129 | 144 |
| 130 Profile* profile = | 145 Profile* profile = |
| 131 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 146 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 132 ExtensionService* service = profile->GetExtensionService(); | 147 ExtensionService* service = profile->GetExtensionService(); |
| 133 if (!service) | 148 if (!service) |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 void ExtensionTabHelper::OnInlineInstallFailure(int install_id, | 384 void ExtensionTabHelper::OnInlineInstallFailure(int install_id, |
| 370 int return_route_id, | 385 int return_route_id, |
| 371 const std::string& error) { | 386 const std::string& error) { |
| 372 Send(new ExtensionMsg_InlineWebstoreInstallResponse( | 387 Send(new ExtensionMsg_InlineWebstoreInstallResponse( |
| 373 return_route_id, install_id, false, error)); | 388 return_route_id, install_id, false, error)); |
| 374 } | 389 } |
| 375 | 390 |
| 376 WebContents* ExtensionTabHelper::GetAssociatedWebContents() const { | 391 WebContents* ExtensionTabHelper::GetAssociatedWebContents() const { |
| 377 return web_contents(); | 392 return web_contents(); |
| 378 } | 393 } |
| OLD | NEW |