OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_message_service.h" | |
8 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h" |
10 #include "chrome/common/extensions/extension_action.h" | 11 #include "chrome/common/extensions/extension_action.h" |
11 #include "chrome/common/extensions/extension_icon_set.h" | 12 #include "chrome/common/extensions/extension_icon_set.h" |
12 #include "chrome/common/extensions/extension_messages.h" | 13 #include "chrome/common/extensions/extension_messages.h" |
13 #include "chrome/common/extensions/extension_resource.h" | 14 #include "chrome/common/extensions/extension_resource.h" |
14 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
15 #include "content/browser/tab_contents/navigation_controller.h" | 16 #include "content/browser/tab_contents/navigation_controller.h" |
16 #include "content/common/notification_service.h" | 17 #include "content/common/notification_service.h" |
17 | 18 |
18 ExtensionTabHelper::ExtensionTabHelper(TabContents* tab_contents) | 19 ExtensionTabHelper::ExtensionTabHelper(TabContentsWrapper* wrapper) |
19 : TabContentsObserver(tab_contents), | 20 : TabContentsObserver(wrapper->tab_contents()), |
20 extension_app_(NULL) { | 21 extension_app_(NULL), |
| 22 wrapper_(wrapper) { |
21 } | 23 } |
22 | 24 |
23 ExtensionTabHelper::~ExtensionTabHelper() { | 25 ExtensionTabHelper::~ExtensionTabHelper() { |
24 } | 26 } |
25 | 27 |
26 void ExtensionTabHelper::CopyStateFrom(const ExtensionTabHelper& source) { | 28 void ExtensionTabHelper::CopyStateFrom(const ExtensionTabHelper& source) { |
27 SetExtensionApp(source.extension_app()); | 29 SetExtensionApp(source.extension_app()); |
28 extension_app_icon_ = source.extension_app_icon_; | 30 extension_app_icon_ = source.extension_app_icon_; |
29 } | 31 } |
30 | 32 |
31 void ExtensionTabHelper::PageActionStateChanged() { | 33 void ExtensionTabHelper::PageActionStateChanged() { |
32 tab_contents()->NotifyNavigationStateChanged( | 34 tab_contents()->NotifyNavigationStateChanged( |
33 TabContents::INVALIDATE_PAGE_ACTIONS); | 35 TabContents::INVALIDATE_PAGE_ACTIONS); |
34 } | 36 } |
35 | 37 |
| 38 void ExtensionTabHelper::GetApplicationInfo(int32 page_id) { |
| 39 Send(new ExtensionMsg_GetApplicationInfo(routing_id(), page_id)); |
| 40 } |
| 41 |
36 void ExtensionTabHelper::SetExtensionApp(const Extension* extension) { | 42 void ExtensionTabHelper::SetExtensionApp(const Extension* extension) { |
37 DCHECK(!extension || extension->GetFullLaunchURL().is_valid()); | 43 DCHECK(!extension || extension->GetFullLaunchURL().is_valid()); |
38 extension_app_ = extension; | 44 extension_app_ = extension; |
39 | 45 |
40 UpdateExtensionAppIcon(extension_app_); | 46 UpdateExtensionAppIcon(extension_app_); |
41 | 47 |
42 NotificationService::current()->Notify( | 48 NotificationService::current()->Notify( |
43 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, | 49 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
44 Source<ExtensionTabHelper>(this), | 50 Source<ExtensionTabHelper>(this), |
45 NotificationService::NoDetails()); | 51 NotificationService::NoDetails()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 page_action->ClearAllValuesForTab( | 102 page_action->ClearAllValuesForTab( |
97 tab_contents()->controller().session_id().id()); | 103 tab_contents()->controller().session_id().id()); |
98 PageActionStateChanged(); | 104 PageActionStateChanged(); |
99 } | 105 } |
100 } | 106 } |
101 } | 107 } |
102 | 108 |
103 bool ExtensionTabHelper::OnMessageReceived(const IPC::Message& message) { | 109 bool ExtensionTabHelper::OnMessageReceived(const IPC::Message& message) { |
104 bool handled = true; | 110 bool handled = true; |
105 IPC_BEGIN_MESSAGE_MAP(ExtensionTabHelper, message) | 111 IPC_BEGIN_MESSAGE_MAP(ExtensionTabHelper, message) |
106 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage) | 112 IPC_MESSAGE_HANDLER(ExtensionHostMsg_DidGetApplicationInfo, |
| 113 OnDidGetApplicationInfo) |
| 114 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InstallApplication, |
| 115 OnInstallApplication) |
107 IPC_MESSAGE_UNHANDLED(handled = false) | 116 IPC_MESSAGE_UNHANDLED(handled = false) |
108 IPC_END_MESSAGE_MAP() | 117 IPC_END_MESSAGE_MAP() |
109 return handled; | 118 return handled; |
110 } | 119 } |
111 | 120 |
| 121 void ExtensionTabHelper::OnDidGetApplicationInfo( |
| 122 int32 page_id, const WebApplicationInfo& info) { |
| 123 web_app_info_ = info; |
| 124 |
| 125 if (wrapper_->delegate()) |
| 126 wrapper_->delegate()->OnDidGetApplicationInfo(wrapper_, page_id); |
| 127 } |
| 128 |
| 129 void ExtensionTabHelper::OnInstallApplication(const WebApplicationInfo& info) { |
| 130 if (wrapper_->delegate()) |
| 131 wrapper_->delegate()->OnInstallApplication(wrapper_, info); |
| 132 } |
| 133 |
112 void ExtensionTabHelper::UpdateExtensionAppIcon(const Extension* extension) { | 134 void ExtensionTabHelper::UpdateExtensionAppIcon(const Extension* extension) { |
113 extension_app_icon_.reset(); | 135 extension_app_icon_.reset(); |
114 | 136 |
115 if (extension) { | 137 if (extension) { |
116 extension_app_image_loader_.reset(new ImageLoadingTracker(this)); | 138 extension_app_image_loader_.reset(new ImageLoadingTracker(this)); |
117 extension_app_image_loader_->LoadImage( | 139 extension_app_image_loader_->LoadImage( |
118 extension, | 140 extension, |
119 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH, | 141 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH, |
120 ExtensionIconSet::MATCH_EXACTLY), | 142 ExtensionIconSet::MATCH_EXACTLY), |
121 gfx::Size(Extension::EXTENSION_ICON_SMALLISH, | 143 gfx::Size(Extension::EXTENSION_ICON_SMALLISH, |
122 Extension::EXTENSION_ICON_SMALLISH), | 144 Extension::EXTENSION_ICON_SMALLISH), |
123 ImageLoadingTracker::CACHE); | 145 ImageLoadingTracker::CACHE); |
124 } else { | 146 } else { |
125 extension_app_image_loader_.reset(NULL); | 147 extension_app_image_loader_.reset(NULL); |
126 } | 148 } |
127 } | 149 } |
128 | 150 |
129 void ExtensionTabHelper::OnImageLoaded(SkBitmap* image, | 151 void ExtensionTabHelper::OnImageLoaded(SkBitmap* image, |
130 const ExtensionResource& resource, | 152 const ExtensionResource& resource, |
131 int index) { | 153 int index) { |
132 if (image) { | 154 if (image) { |
133 extension_app_icon_ = *image; | 155 extension_app_icon_ = *image; |
134 tab_contents()->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB); | 156 tab_contents()->NotifyNavigationStateChanged(TabContents::INVALIDATE_TAB); |
135 } | 157 } |
136 } | 158 } |
137 | |
138 void ExtensionTabHelper::OnPostMessage(int port_id, | |
139 const std::string& message) { | |
140 if (tab_contents()->profile()->GetExtensionMessageService()) { | |
141 tab_contents()->profile()->GetExtensionMessageService()-> | |
142 PostMessageFromRenderer(port_id, message); | |
143 } | |
144 } | |
OLD | NEW |