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/webstore_inline_installer.h" | 8 #include "chrome/browser/extensions/webstore_inline_installer.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/sessions/restore_tab_helper.h" | 10 #include "chrome/browser/sessions/restore_tab_helper.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 UpdateExtensionAppIcon(extension_app_); | 60 UpdateExtensionAppIcon(extension_app_); |
61 | 61 |
62 content::NotificationService::current()->Notify( | 62 content::NotificationService::current()->Notify( |
63 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, | 63 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
64 content::Source<ExtensionTabHelper>(this), | 64 content::Source<ExtensionTabHelper>(this), |
65 content::NotificationService::NoDetails()); | 65 content::NotificationService::NoDetails()); |
66 } | 66 } |
67 | 67 |
68 void ExtensionTabHelper::SetExtensionAppById( | 68 void ExtensionTabHelper::SetExtensionAppById( |
69 const std::string& extension_app_id) { | 69 const std::string& extension_app_id) { |
70 if (extension_app_id.empty()) | 70 const Extension* extension = GetExtension(extension_app_id); |
71 return; | |
72 | |
73 Profile* profile = | |
74 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | |
75 ExtensionService* extension_service = profile->GetExtensionService(); | |
76 if (!extension_service || !extension_service->is_ready()) | |
77 return; | |
78 | |
79 const Extension* extension = | |
80 extension_service->GetExtensionById(extension_app_id, false); | |
81 if (extension) | 71 if (extension) |
82 SetExtensionApp(extension); | 72 SetExtensionApp(extension); |
83 } | 73 } |
84 | 74 |
| 75 void ExtensionTabHelper::SetExtensionAppIconById( |
| 76 const std::string& extension_app_id) { |
| 77 const Extension* extension = GetExtension(extension_app_id); |
| 78 if (extension) |
| 79 UpdateExtensionAppIcon(extension); |
| 80 } |
| 81 |
85 SkBitmap* ExtensionTabHelper::GetExtensionAppIcon() { | 82 SkBitmap* ExtensionTabHelper::GetExtensionAppIcon() { |
86 if (extension_app_icon_.empty()) | 83 if (extension_app_icon_.empty()) |
87 return NULL; | 84 return NULL; |
88 | 85 |
89 return &extension_app_icon_; | 86 return &extension_app_icon_; |
90 } | 87 } |
91 | 88 |
92 void ExtensionTabHelper::DidNavigateMainFrame( | 89 void ExtensionTabHelper::DidNavigateMainFrame( |
93 const content::LoadCommittedDetails& details, | 90 const content::LoadCommittedDetails& details, |
94 const content::FrameNavigateParams& params) { | 91 const content::FrameNavigateParams& params) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 Send(new ExtensionMsg_GetAppNotifyChannelResponse( | 225 Send(new ExtensionMsg_GetAppNotifyChannelResponse( |
229 setup->return_route_id(), channel_id, error, setup->callback_id())); | 226 setup->return_route_id(), channel_id, error, setup->callback_id())); |
230 } | 227 } |
231 | 228 |
232 void ExtensionTabHelper::OnRequest( | 229 void ExtensionTabHelper::OnRequest( |
233 const ExtensionHostMsg_Request_Params& request) { | 230 const ExtensionHostMsg_Request_Params& request) { |
234 extension_function_dispatcher_.Dispatch(request, | 231 extension_function_dispatcher_.Dispatch(request, |
235 web_contents()->GetRenderViewHost()); | 232 web_contents()->GetRenderViewHost()); |
236 } | 233 } |
237 | 234 |
| 235 const Extension* ExtensionTabHelper::GetExtension( |
| 236 const std::string& extension_app_id) { |
| 237 if (extension_app_id.empty()) |
| 238 return NULL; |
| 239 |
| 240 Profile* profile = |
| 241 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 242 ExtensionService* extension_service = profile->GetExtensionService(); |
| 243 if (!extension_service || !extension_service->is_ready()) |
| 244 return NULL; |
| 245 |
| 246 const Extension* extension = |
| 247 extension_service->GetExtensionById(extension_app_id, false); |
| 248 return extension; |
| 249 } |
| 250 |
238 void ExtensionTabHelper::UpdateExtensionAppIcon(const Extension* extension) { | 251 void ExtensionTabHelper::UpdateExtensionAppIcon(const Extension* extension) { |
239 extension_app_icon_.reset(); | 252 extension_app_icon_.reset(); |
240 | 253 |
241 if (extension) { | 254 if (extension) { |
242 extension_app_image_loader_.reset(new ImageLoadingTracker(this)); | 255 extension_app_image_loader_.reset(new ImageLoadingTracker(this)); |
243 extension_app_image_loader_->LoadImage( | 256 extension_app_image_loader_->LoadImage( |
244 extension, | 257 extension, |
245 extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALLISH, | 258 extension->GetIconResource(ExtensionIconSet::EXTENSION_ICON_SMALLISH, |
246 ExtensionIconSet::MATCH_EXACTLY), | 259 ExtensionIconSet::MATCH_EXACTLY), |
247 gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALLISH, | 260 gfx::Size(ExtensionIconSet::EXTENSION_ICON_SMALLISH, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 void ExtensionTabHelper::OnInlineInstallFailure(int install_id, | 299 void ExtensionTabHelper::OnInlineInstallFailure(int install_id, |
287 int return_route_id, | 300 int return_route_id, |
288 const std::string& error) { | 301 const std::string& error) { |
289 Send(new ExtensionMsg_InlineWebstoreInstallResponse( | 302 Send(new ExtensionMsg_InlineWebstoreInstallResponse( |
290 return_route_id, install_id, false, error)); | 303 return_route_id, install_id, false, error)); |
291 } | 304 } |
292 | 305 |
293 WebContents* ExtensionTabHelper::GetAssociatedWebContents() const { | 306 WebContents* ExtensionTabHelper::GetAssociatedWebContents() const { |
294 return web_contents(); | 307 return web_contents(); |
295 } | 308 } |
OLD | NEW |