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