| 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/ui/intents/web_intent_picker_controller.h" | 5 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/extensions/webstore_installer.h" | 13 #include "chrome/browser/extensions/webstore_installer.h" |
| 14 #include "chrome/browser/favicon/favicon_service.h" | 14 #include "chrome/browser/favicon/favicon_service.h" |
| 15 #include "chrome/browser/intents/cws_intents_registry_factory.h" | 15 #include "chrome/browser/intents/cws_intents_registry_factory.h" |
| 16 #include "chrome/browser/intents/default_web_intent_service.h" | 16 #include "chrome/browser/intents/default_web_intent_service.h" |
| 17 #include "chrome/browser/intents/web_intents_registry_factory.h" | 17 #include "chrome/browser/intents/web_intents_registry_factory.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/tab_contents/tab_util.h" | 19 #include "chrome/browser/tab_contents/tab_util.h" |
| 20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
| 22 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 23 #include "chrome/browser/ui/browser_navigator.h" | 23 #include "chrome/browser/ui/browser_navigator.h" |
| 24 #include "chrome/browser/ui/intents/web_intent_picker.h" | 24 #include "chrome/browser/ui/intents/web_intent_picker.h" |
| 25 #include "chrome/browser/ui/intents/web_intent_picker_model.h" | 25 #include "chrome/browser/ui/intents/web_intent_picker_model.h" |
| 26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 26 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 28 #include "chrome/browser/webdata/web_data_service.h" | 28 #include "chrome/browser/webdata/web_data_service.h" |
| 29 #include "chrome/common/chrome_notification_types.h" | 29 #include "chrome/common/chrome_notification_types.h" |
| 30 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/navigation_controller.h" | 32 #include "content/public/browser/navigation_controller.h" |
| 33 #include "content/public/browser/notification_source.h" | 33 #include "content/public/browser/notification_source.h" |
| 34 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 35 #include "content/public/browser/web_intents_dispatcher.h" | 35 #include "content/public/browser/web_intents_dispatcher.h" |
| 36 #include "content/public/common/url_fetcher.h" | 36 #include "content/public/common/url_fetcher.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 const char kShareActionURL[] = "http://webintents.org/share"; | 49 const char kShareActionURL[] = "http://webintents.org/share"; |
| 50 const char kEditActionURL[] = "http://webintents.org/edit"; | 50 const char kEditActionURL[] = "http://webintents.org/edit"; |
| 51 const char kViewActionURL[] = "http://webintents.org/view"; | 51 const char kViewActionURL[] = "http://webintents.org/view"; |
| 52 const char kPickActionURL[] = "http://webintents.org/pick"; | 52 const char kPickActionURL[] = "http://webintents.org/pick"; |
| 53 const char kSubscribeActionURL[] = "http://webintents.org/subscribe"; | 53 const char kSubscribeActionURL[] = "http://webintents.org/subscribe"; |
| 54 const char kSaveActionURL[] = "http://webintents.org/save"; | 54 const char kSaveActionURL[] = "http://webintents.org/save"; |
| 55 | 55 |
| 56 // Gets the favicon service for the profile in |tab_contents|. | 56 // Gets the favicon service for the profile in |tab_contents|. |
| 57 FaviconService* GetFaviconService(TabContentsWrapper* wrapper) { | 57 FaviconService* GetFaviconService(TabContents* tab_contents) { |
| 58 return wrapper->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); | 58 return tab_contents->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Gets the web intents registry for the profile in |tab_contents|. | 61 // Gets the web intents registry for the profile in |tab_contents|. |
| 62 WebIntentsRegistry* GetWebIntentsRegistry(TabContentsWrapper* wrapper) { | 62 WebIntentsRegistry* GetWebIntentsRegistry(TabContents* tab_contents) { |
| 63 return WebIntentsRegistryFactory::GetForProfile(wrapper->profile()); | 63 return WebIntentsRegistryFactory::GetForProfile(tab_contents->profile()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Gets the Chrome web store intents registry for the profile in |tab_contents|. | 66 // Gets the Chrome web store intents registry for the profile in |tab_contents|. |
| 67 CWSIntentsRegistry* GetCWSIntentsRegistry(TabContentsWrapper* wrapper) { | 67 CWSIntentsRegistry* GetCWSIntentsRegistry(TabContents* tab_contents) { |
| 68 return CWSIntentsRegistryFactory::GetForProfile(wrapper->profile()); | 68 return CWSIntentsRegistryFactory::GetForProfile(tab_contents->profile()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 WebIntentPickerModel::Disposition ConvertDisposition( | 71 WebIntentPickerModel::Disposition ConvertDisposition( |
| 72 webkit_glue::WebIntentServiceData::Disposition disposition) { | 72 webkit_glue::WebIntentServiceData::Disposition disposition) { |
| 73 switch (disposition) { | 73 switch (disposition) { |
| 74 case webkit_glue::WebIntentServiceData::DISPOSITION_INLINE: | 74 case webkit_glue::WebIntentServiceData::DISPOSITION_INLINE: |
| 75 return WebIntentPickerModel::DISPOSITION_INLINE; | 75 return WebIntentPickerModel::DISPOSITION_INLINE; |
| 76 case webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW: | 76 case webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW: |
| 77 return WebIntentPickerModel::DISPOSITION_WINDOW; | 77 return WebIntentPickerModel::DISPOSITION_WINDOW; |
| 78 default: | 78 default: |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 const net::URLFetcher* source) { | 127 const net::URLFetcher* source) { |
| 128 DCHECK(!callback_.is_null()); | 128 DCHECK(!callback_.is_null()); |
| 129 callback_.Run(source); | 129 callback_.Run(source); |
| 130 delete source; | 130 delete source; |
| 131 delete this; | 131 delete this; |
| 132 } | 132 } |
| 133 | 133 |
| 134 } // namespace | 134 } // namespace |
| 135 | 135 |
| 136 WebIntentPickerController::WebIntentPickerController( | 136 WebIntentPickerController::WebIntentPickerController( |
| 137 TabContentsWrapper* wrapper) | 137 TabContents* tab_contents) |
| 138 : wrapper_(wrapper), | 138 : tab_contents_(tab_contents), |
| 139 picker_(NULL), | 139 picker_(NULL), |
| 140 picker_model_(new WebIntentPickerModel()), | 140 picker_model_(new WebIntentPickerModel()), |
| 141 pending_async_count_(0), | 141 pending_async_count_(0), |
| 142 pending_registry_calls_count_(0), | 142 pending_registry_calls_count_(0), |
| 143 picker_shown_(false), | 143 picker_shown_(false), |
| 144 intents_dispatcher_(NULL), | 144 intents_dispatcher_(NULL), |
| 145 service_tab_(NULL), | 145 service_tab_(NULL), |
| 146 weak_ptr_factory_(this) { | 146 weak_ptr_factory_(this) { |
| 147 content::NavigationController* controller = | 147 content::NavigationController* controller = |
| 148 &wrapper->web_contents()->GetController(); | 148 &tab_contents->web_contents()->GetController(); |
| 149 registrar_.Add(this, content::NOTIFICATION_LOAD_START, | 149 registrar_.Add(this, content::NOTIFICATION_LOAD_START, |
| 150 content::Source<content::NavigationController>(controller)); | 150 content::Source<content::NavigationController>(controller)); |
| 151 registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING, | 151 registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING, |
| 152 content::Source<content::NavigationController>(controller)); | 152 content::Source<content::NavigationController>(controller)); |
| 153 } | 153 } |
| 154 | 154 |
| 155 WebIntentPickerController::~WebIntentPickerController() { | 155 WebIntentPickerController::~WebIntentPickerController() { |
| 156 } | 156 } |
| 157 | 157 |
| 158 // TODO(gbillock): combine this with ShowDialog. | 158 // TODO(gbillock): combine this with ShowDialog. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 174 if (intents_dispatcher_) { | 174 if (intents_dispatcher_) { |
| 175 intents_dispatcher_->SendReplyMessage( | 175 intents_dispatcher_->SendReplyMessage( |
| 176 webkit_glue::WEB_INTENT_REPLY_FAILURE, | 176 webkit_glue::WEB_INTENT_REPLY_FAILURE, |
| 177 ASCIIToUTF16("Simultaneous intent invocation.")); | 177 ASCIIToUTF16("Simultaneous intent invocation.")); |
| 178 } | 178 } |
| 179 return; | 179 return; |
| 180 } | 180 } |
| 181 | 181 |
| 182 // TODO(binji): Figure out what to do when intents are invoked from incognito | 182 // TODO(binji): Figure out what to do when intents are invoked from incognito |
| 183 // mode. | 183 // mode. |
| 184 if (wrapper_->profile()->IsOffTheRecord()) { | 184 if (tab_contents_->profile()->IsOffTheRecord()) { |
| 185 if (intents_dispatcher_) { | 185 if (intents_dispatcher_) { |
| 186 intents_dispatcher_->SendReplyMessage( | 186 intents_dispatcher_->SendReplyMessage( |
| 187 webkit_glue::WEB_INTENT_REPLY_FAILURE, string16()); | 187 webkit_glue::WEB_INTENT_REPLY_FAILURE, string16()); |
| 188 } | 188 } |
| 189 return; | 189 return; |
| 190 } | 190 } |
| 191 | 191 |
| 192 picker_model_->Clear(); | 192 picker_model_->Clear(); |
| 193 picker_model_->set_action(action); | 193 picker_model_->set_action(action); |
| 194 picker_model_->set_mimetype(type); | 194 picker_model_->set_mimetype(type); |
| 195 | 195 |
| 196 // If the intent is explicit, skip showing the picker. | 196 // If the intent is explicit, skip showing the picker. |
| 197 if (intents_dispatcher_) { | 197 if (intents_dispatcher_) { |
| 198 const GURL& service = intents_dispatcher_->GetIntent().service; | 198 const GURL& service = intents_dispatcher_->GetIntent().service; |
| 199 if (service.is_valid()) { | 199 if (service.is_valid()) { |
| 200 // TODO(gbillock): When we can parse pages for the intent tag, | 200 // TODO(gbillock): When we can parse pages for the intent tag, |
| 201 // take out this requirement that explicit intents dispatch to | 201 // take out this requirement that explicit intents dispatch to |
| 202 // extension urls. | 202 // extension urls. |
| 203 if (!service.SchemeIs(chrome::kExtensionScheme)) { | 203 if (!service.SchemeIs(chrome::kExtensionScheme)) { |
| 204 intents_dispatcher_->SendReplyMessage( | 204 intents_dispatcher_->SendReplyMessage( |
| 205 webkit_glue::WEB_INTENT_REPLY_FAILURE, ASCIIToUTF16( | 205 webkit_glue::WEB_INTENT_REPLY_FAILURE, ASCIIToUTF16( |
| 206 "Only extension urls are supported for explicit invocation")); | 206 "Only extension urls are supported for explicit invocation")); |
| 207 return; | 207 return; |
| 208 } | 208 } |
| 209 | 209 |
| 210 // Get services from the registry to verify a registered extension | 210 // Get services from the registry to verify a registered extension |
| 211 // page for this action/type if it is permitted to be dispatched. (Also | 211 // page for this action/type if it is permitted to be dispatched. (Also |
| 212 // required to find disposition set by service.) | 212 // required to find disposition set by service.) |
| 213 pending_async_count_++; | 213 pending_async_count_++; |
| 214 GetWebIntentsRegistry(wrapper_)->GetIntentServices( | 214 GetWebIntentsRegistry(tab_contents_)->GetIntentServices( |
| 215 action, type, base::Bind( | 215 action, type, base::Bind( |
| 216 &WebIntentPickerController::WebIntentServicesForExplicitIntent, | 216 &WebIntentPickerController::WebIntentServicesForExplicitIntent, |
| 217 weak_ptr_factory_.GetWeakPtr())); | 217 weak_ptr_factory_.GetWeakPtr())); |
| 218 return; | 218 return; |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 pending_async_count_ += 2; | 222 pending_async_count_ += 2; |
| 223 pending_registry_calls_count_ += 1; | 223 pending_registry_calls_count_ += 1; |
| 224 | 224 |
| 225 GetWebIntentsRegistry(wrapper_)->GetIntentServices( | 225 GetWebIntentsRegistry(tab_contents_)->GetIntentServices( |
| 226 action, type, | 226 action, type, |
| 227 base::Bind(&WebIntentPickerController::OnWebIntentServicesAvailable, | 227 base::Bind(&WebIntentPickerController::OnWebIntentServicesAvailable, |
| 228 weak_ptr_factory_.GetWeakPtr())); | 228 weak_ptr_factory_.GetWeakPtr())); |
| 229 | 229 |
| 230 GURL invoking_url = wrapper_->web_contents()->GetURL(); | 230 GURL invoking_url = tab_contents_->web_contents()->GetURL(); |
| 231 if (invoking_url.is_valid()) { | 231 if (invoking_url.is_valid()) { |
| 232 pending_async_count_++; | 232 pending_async_count_++; |
| 233 pending_registry_calls_count_++; | 233 pending_registry_calls_count_++; |
| 234 GetWebIntentsRegistry(wrapper_)->GetDefaultIntentService( | 234 GetWebIntentsRegistry(tab_contents_)->GetDefaultIntentService( |
| 235 action, type, invoking_url, | 235 action, type, invoking_url, |
| 236 base::Bind(&WebIntentPickerController::OnWebIntentDefaultsAvailable, | 236 base::Bind(&WebIntentPickerController::OnWebIntentDefaultsAvailable, |
| 237 weak_ptr_factory_.GetWeakPtr())); | 237 weak_ptr_factory_.GetWeakPtr())); |
| 238 } | 238 } |
| 239 | 239 |
| 240 GetCWSIntentsRegistry(wrapper_)->GetIntentServices( | 240 GetCWSIntentsRegistry(tab_contents_)->GetIntentServices( |
| 241 action, type, | 241 action, type, |
| 242 base::Bind(&WebIntentPickerController::OnCWSIntentServicesAvailable, | 242 base::Bind(&WebIntentPickerController::OnCWSIntentServicesAvailable, |
| 243 weak_ptr_factory_.GetWeakPtr())); | 243 weak_ptr_factory_.GetWeakPtr())); |
| 244 } | 244 } |
| 245 | 245 |
| 246 void WebIntentPickerController::Observe( | 246 void WebIntentPickerController::Observe( |
| 247 int type, | 247 int type, |
| 248 const content::NotificationSource& source, | 248 const content::NotificationSource& source, |
| 249 const content::NotificationDetails& details) { | 249 const content::NotificationDetails& details) { |
| 250 DCHECK(type == content::NOTIFICATION_LOAD_START || | 250 DCHECK(type == content::NOTIFICATION_LOAD_START || |
| 251 type == chrome::NOTIFICATION_TAB_CLOSING); | 251 type == chrome::NOTIFICATION_TAB_CLOSING); |
| 252 ClosePicker(); | 252 ClosePicker(); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void WebIntentPickerController::OnServiceChosen(const GURL& url, | 255 void WebIntentPickerController::OnServiceChosen(const GURL& url, |
| 256 Disposition disposition) { | 256 Disposition disposition) { |
| 257 switch (disposition) { | 257 switch (disposition) { |
| 258 case WebIntentPickerModel::DISPOSITION_INLINE: | 258 case WebIntentPickerModel::DISPOSITION_INLINE: |
| 259 // Set the model to inline disposition. It will notify the picker which | 259 // Set the model to inline disposition. It will notify the picker which |
| 260 // will respond (via OnInlineDispositionWebContentsCreated) with the | 260 // will respond (via OnInlineDispositionWebContentsCreated) with the |
| 261 // WebContents to dispatch the intent to. | 261 // WebContents to dispatch the intent to. |
| 262 picker_model_->SetInlineDisposition(url); | 262 picker_model_->SetInlineDisposition(url); |
| 263 break; | 263 break; |
| 264 | 264 |
| 265 case WebIntentPickerModel::DISPOSITION_WINDOW: { | 265 case WebIntentPickerModel::DISPOSITION_WINDOW: { |
| 266 int index = TabStripModel::kNoTab; | 266 int index = TabStripModel::kNoTab; |
| 267 Browser* browser = browser::FindBrowserForController( | 267 Browser* browser = browser::FindBrowserForController( |
| 268 &wrapper_->web_contents()->GetController(), &index); | 268 &tab_contents_->web_contents()->GetController(), &index); |
| 269 TabContentsWrapper* contents = Browser::TabContentsFactory( | 269 TabContents* contents = Browser::TabContentsFactory( |
| 270 wrapper_->profile(), | 270 tab_contents_->profile(), |
| 271 tab_util::GetSiteInstanceForNewTab( | 271 tab_util::GetSiteInstanceForNewTab( |
| 272 wrapper_->profile(), url), | 272 tab_contents_->profile(), url), |
| 273 MSG_ROUTING_NONE, NULL, NULL); | 273 MSG_ROUTING_NONE, NULL, NULL); |
| 274 | 274 |
| 275 intents_dispatcher_->DispatchIntent(contents->web_contents()); | 275 intents_dispatcher_->DispatchIntent(contents->web_contents()); |
| 276 service_tab_ = contents->web_contents(); | 276 service_tab_ = contents->web_contents(); |
| 277 | 277 |
| 278 // This call performs all the tab strip manipulation, notifications, etc. | 278 // This call performs all the tab strip manipulation, notifications, etc. |
| 279 // Since we're passing in a target_contents, it assumes that we will | 279 // Since we're passing in a target_contents, it assumes that we will |
| 280 // navigate the page ourselves, though. | 280 // navigate the page ourselves, though. |
| 281 browser::NavigateParams params(browser, | 281 browser::NavigateParams params(browser, |
| 282 url, | 282 url, |
| 283 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 283 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 284 params.target_contents = contents; | 284 params.target_contents = contents; |
| 285 params.disposition = NEW_FOREGROUND_TAB; | 285 params.disposition = NEW_FOREGROUND_TAB; |
| 286 params.profile = wrapper_->profile(); | 286 params.profile = tab_contents_->profile(); |
| 287 browser::Navigate(¶ms); | 287 browser::Navigate(¶ms); |
| 288 | 288 |
| 289 service_tab_->GetController().LoadURL( | 289 service_tab_->GetController().LoadURL( |
| 290 url, content::Referrer(), | 290 url, content::Referrer(), |
| 291 content::PAGE_TRANSITION_AUTO_BOOKMARK, std::string()); | 291 content::PAGE_TRANSITION_AUTO_BOOKMARK, std::string()); |
| 292 | 292 |
| 293 ClosePicker(); | 293 ClosePicker(); |
| 294 break; | 294 break; |
| 295 } | 295 } |
| 296 | 296 |
| 297 default: | 297 default: |
| 298 NOTREACHED(); | 298 NOTREACHED(); |
| 299 break; | 299 break; |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 | 302 |
| 303 void WebIntentPickerController::OnInlineDispositionWebContentsCreated( | 303 void WebIntentPickerController::OnInlineDispositionWebContentsCreated( |
| 304 content::WebContents* web_contents) { | 304 content::WebContents* web_contents) { |
| 305 if (web_contents) | 305 if (web_contents) |
| 306 intents_dispatcher_->DispatchIntent(web_contents); | 306 intents_dispatcher_->DispatchIntent(web_contents); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void WebIntentPickerController::OnExtensionInstallRequested( | 309 void WebIntentPickerController::OnExtensionInstallRequested( |
| 310 const std::string& id) { | 310 const std::string& id) { |
| 311 scoped_ptr<WebstoreInstaller::Approval> approval( | 311 scoped_ptr<WebstoreInstaller::Approval> approval( |
| 312 WebstoreInstaller::Approval::CreateWithInstallPrompt( | 312 WebstoreInstaller::Approval::CreateWithInstallPrompt( |
| 313 wrapper_->profile())); | 313 tab_contents_->profile())); |
| 314 | 314 |
| 315 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( | 315 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( |
| 316 wrapper_->profile(), this, &wrapper_->web_contents()->GetController(), id, | 316 tab_contents_->profile(), this, |
| 317 &tab_contents_->web_contents()->GetController(), id, |
| 317 approval.Pass(), WebstoreInstaller::FLAG_INLINE_INSTALL); | 318 approval.Pass(), WebstoreInstaller::FLAG_INLINE_INSTALL); |
| 318 | 319 |
| 319 pending_async_count_++; | 320 pending_async_count_++; |
| 320 installer->Start(); | 321 installer->Start(); |
| 321 } | 322 } |
| 322 | 323 |
| 323 void WebIntentPickerController::OnExtensionLinkClicked(const std::string& id) { | 324 void WebIntentPickerController::OnExtensionLinkClicked(const std::string& id) { |
| 324 // Navigate from source tab. | 325 // Navigate from source tab. |
| 325 Browser* browser = | 326 Browser* browser = |
| 326 browser::FindBrowserWithWebContents(wrapper_->web_contents()); | 327 browser::FindBrowserWithWebContents(tab_contents_->web_contents()); |
| 327 GURL extension_url(extension_urls::GetWebstoreItemDetailURLPrefix() + id); | 328 GURL extension_url(extension_urls::GetWebstoreItemDetailURLPrefix() + id); |
| 328 browser::NavigateParams params(browser, extension_url, | 329 browser::NavigateParams params(browser, extension_url, |
| 329 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 330 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 330 params.disposition = NEW_FOREGROUND_TAB; | 331 params.disposition = NEW_FOREGROUND_TAB; |
| 331 browser::Navigate(¶ms); | 332 browser::Navigate(¶ms); |
| 332 } | 333 } |
| 333 | 334 |
| 334 void WebIntentPickerController::OnSuggestionsLinkClicked() { | 335 void WebIntentPickerController::OnSuggestionsLinkClicked() { |
| 335 // Navigate from source tab. | 336 // Navigate from source tab. |
| 336 Browser* browser = | 337 Browser* browser = |
| 337 browser::FindBrowserWithWebContents(wrapper_->web_contents()); | 338 browser::FindBrowserWithWebContents(tab_contents_->web_contents()); |
| 338 GURL query_url = extension_urls::GetWebstoreIntentQueryURL( | 339 GURL query_url = extension_urls::GetWebstoreIntentQueryURL( |
| 339 UTF16ToUTF8(picker_model_->action()), | 340 UTF16ToUTF8(picker_model_->action()), |
| 340 UTF16ToUTF8(picker_model_->mimetype())); | 341 UTF16ToUTF8(picker_model_->mimetype())); |
| 341 browser::NavigateParams params(browser, query_url, | 342 browser::NavigateParams params(browser, query_url, |
| 342 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 343 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 343 params.disposition = NEW_FOREGROUND_TAB; | 344 params.disposition = NEW_FOREGROUND_TAB; |
| 344 browser::Navigate(¶ms); | 345 browser::Navigate(¶ms); |
| 345 } | 346 } |
| 346 | 347 |
| 347 void WebIntentPickerController::OnPickerClosed() { | 348 void WebIntentPickerController::OnPickerClosed() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 368 | 369 |
| 369 void WebIntentPickerController::OnClosing() { | 370 void WebIntentPickerController::OnClosing() { |
| 370 picker_shown_ = false; | 371 picker_shown_ = false; |
| 371 picker_ = NULL; | 372 picker_ = NULL; |
| 372 } | 373 } |
| 373 | 374 |
| 374 void WebIntentPickerController::OnExtensionInstallSuccess( | 375 void WebIntentPickerController::OnExtensionInstallSuccess( |
| 375 const std::string& id) { | 376 const std::string& id) { |
| 376 picker_->OnExtensionInstallSuccess(id); | 377 picker_->OnExtensionInstallSuccess(id); |
| 377 pending_async_count_++; | 378 pending_async_count_++; |
| 378 GetWebIntentsRegistry(wrapper_)->GetIntentServicesForExtensionFilter( | 379 GetWebIntentsRegistry(tab_contents_)->GetIntentServicesForExtensionFilter( |
| 379 picker_model_->action(), | 380 picker_model_->action(), |
| 380 picker_model_->mimetype(), | 381 picker_model_->mimetype(), |
| 381 id, | 382 id, |
| 382 base::Bind( | 383 base::Bind( |
| 383 &WebIntentPickerController::OnExtensionInstallServiceAvailable, | 384 &WebIntentPickerController::OnExtensionInstallServiceAvailable, |
| 384 weak_ptr_factory_.GetWeakPtr())); | 385 weak_ptr_factory_.GetWeakPtr())); |
| 385 AsyncOperationFinished(); | 386 AsyncOperationFinished(); |
| 386 } | 387 } |
| 387 | 388 |
| 388 void WebIntentPickerController::OnExtensionInstallFailure( | 389 void WebIntentPickerController::OnExtensionInstallFailure( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 400 reply_type != webkit_glue::WEB_INTENT_SERVICE_CONTENTS_CLOSED) { | 401 reply_type != webkit_glue::WEB_INTENT_SERVICE_CONTENTS_CLOSED) { |
| 401 int index = TabStripModel::kNoTab; | 402 int index = TabStripModel::kNoTab; |
| 402 Browser* browser = browser::FindBrowserForController( | 403 Browser* browser = browser::FindBrowserForController( |
| 403 &service_tab_->GetController(), &index); | 404 &service_tab_->GetController(), &index); |
| 404 if (browser) { | 405 if (browser) { |
| 405 browser->tab_strip_model()->CloseTabContentsAt( | 406 browser->tab_strip_model()->CloseTabContentsAt( |
| 406 index, TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); | 407 index, TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); |
| 407 | 408 |
| 408 // Activate source tab. | 409 // Activate source tab. |
| 409 Browser* source_browser = | 410 Browser* source_browser = |
| 410 browser::FindBrowserWithWebContents(wrapper_->web_contents()); | 411 browser::FindBrowserWithWebContents(tab_contents_->web_contents()); |
| 411 if (source_browser) { | 412 if (source_browser) { |
| 412 int source_index = | 413 int source_index = source_browser->tab_strip_model()-> |
| 413 source_browser->tab_strip_model()->GetIndexOfTabContents(wrapper_); | 414 GetIndexOfTabContents(tab_contents_); |
| 414 source_browser->ActivateTabAt(source_index, false); | 415 source_browser->ActivateTabAt(source_index, false); |
| 415 } | 416 } |
| 416 } | 417 } |
| 417 service_tab_ = NULL; | 418 service_tab_ = NULL; |
| 418 } | 419 } |
| 419 | 420 |
| 420 intents_dispatcher_ = NULL; | 421 intents_dispatcher_ = NULL; |
| 421 } | 422 } |
| 422 | 423 |
| 423 void WebIntentPickerController::OnWebIntentServicesAvailable( | 424 void WebIntentPickerController::OnWebIntentServicesAvailable( |
| 424 const std::vector<webkit_glue::WebIntentServiceData>& services) { | 425 const std::vector<webkit_glue::WebIntentServiceData>& services) { |
| 425 FaviconService* favicon_service = GetFaviconService(wrapper_); | 426 FaviconService* favicon_service = GetFaviconService(tab_contents_); |
| 426 for (size_t i = 0; i < services.size(); ++i) { | 427 for (size_t i = 0; i < services.size(); ++i) { |
| 427 picker_model_->AddInstalledService( | 428 picker_model_->AddInstalledService( |
| 428 services[i].title, | 429 services[i].title, |
| 429 services[i].service_url, | 430 services[i].service_url, |
| 430 ConvertDisposition(services[i].disposition)); | 431 ConvertDisposition(services[i].disposition)); |
| 431 | 432 |
| 432 pending_async_count_++; | 433 pending_async_count_++; |
| 433 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 434 FaviconService::Handle handle = favicon_service->GetFaviconForURL( |
| 434 services[i].service_url, | 435 services[i].service_url, |
| 435 history::FAVICON, | 436 history::FAVICON, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 451 for (size_t i = 0; i < services.size(); ++i) { | 452 for (size_t i = 0; i < services.size(); ++i) { |
| 452 if (services[i].service_url != intents_dispatcher_->GetIntent().service) | 453 if (services[i].service_url != intents_dispatcher_->GetIntent().service) |
| 453 continue; | 454 continue; |
| 454 | 455 |
| 455 picker_model_->AddInstalledService( | 456 picker_model_->AddInstalledService( |
| 456 services[i].title, | 457 services[i].title, |
| 457 services[i].service_url, | 458 services[i].service_url, |
| 458 ConvertDisposition(services[i].disposition)); | 459 ConvertDisposition(services[i].disposition)); |
| 459 | 460 |
| 460 pending_async_count_++; | 461 pending_async_count_++; |
| 461 FaviconService* favicon_service = GetFaviconService(wrapper_); | 462 FaviconService* favicon_service = GetFaviconService(tab_contents_); |
| 462 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 463 FaviconService::Handle handle = favicon_service->GetFaviconForURL( |
| 463 services[i].service_url, | 464 services[i].service_url, |
| 464 history::FAVICON, | 465 history::FAVICON, |
| 465 &favicon_consumer_, | 466 &favicon_consumer_, |
| 466 base::Bind( | 467 base::Bind( |
| 467 &WebIntentPickerController::OnFaviconDataAvailable, | 468 &WebIntentPickerController::OnFaviconDataAvailable, |
| 468 weak_ptr_factory_.GetWeakPtr())); | 469 weak_ptr_factory_.GetWeakPtr())); |
| 469 favicon_consumer_.SetClientData( | 470 favicon_consumer_.SetClientData( |
| 470 favicon_service, handle, | 471 favicon_service, handle, |
| 471 picker_model_->GetInstalledServiceCount() - 1); | 472 picker_model_->GetInstalledServiceCount() - 1); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 return; | 539 return; |
| 539 } | 540 } |
| 540 } | 541 } |
| 541 | 542 |
| 542 AsyncOperationFinished(); | 543 AsyncOperationFinished(); |
| 543 } | 544 } |
| 544 | 545 |
| 545 void WebIntentPickerController::OnCWSIntentServicesAvailable( | 546 void WebIntentPickerController::OnCWSIntentServicesAvailable( |
| 546 const CWSIntentsRegistry::IntentExtensionList& extensions) { | 547 const CWSIntentsRegistry::IntentExtensionList& extensions) { |
| 547 ExtensionServiceInterface* extension_service = | 548 ExtensionServiceInterface* extension_service = |
| 548 wrapper_->profile()->GetExtensionService(); | 549 tab_contents_->profile()->GetExtensionService(); |
| 549 for (size_t i = 0; i < extensions.size(); ++i) { | 550 for (size_t i = 0; i < extensions.size(); ++i) { |
| 550 const CWSIntentsRegistry::IntentExtensionInfo& info = extensions[i]; | 551 const CWSIntentsRegistry::IntentExtensionInfo& info = extensions[i]; |
| 551 if (extension_service->GetExtensionById(UTF16ToUTF8(info.id), | 552 if (extension_service->GetExtensionById(UTF16ToUTF8(info.id), |
| 552 true)) { // Include disabled. | 553 true)) { // Include disabled. |
| 553 continue; | 554 continue; |
| 554 } | 555 } |
| 555 | 556 |
| 556 picker_model_->AddSuggestedExtension( | 557 picker_model_->AddSuggestedExtension( |
| 557 info.name, | 558 info.name, |
| 558 info.id, | 559 info.id, |
| 559 info.average_rating); | 560 info.average_rating); |
| 560 | 561 |
| 561 pending_async_count_++; | 562 pending_async_count_++; |
| 562 net::URLFetcher* icon_url_fetcher = content::URLFetcher::Create( | 563 net::URLFetcher* icon_url_fetcher = content::URLFetcher::Create( |
| 563 0, | 564 0, |
| 564 info.icon_url, | 565 info.icon_url, |
| 565 net::URLFetcher::GET, | 566 net::URLFetcher::GET, |
| 566 new URLFetcherTrampoline( | 567 new URLFetcherTrampoline( |
| 567 base::Bind( | 568 base::Bind( |
| 568 &WebIntentPickerController::OnExtensionIconURLFetchComplete, | 569 &WebIntentPickerController::OnExtensionIconURLFetchComplete, |
| 569 weak_ptr_factory_.GetWeakPtr(), info.id))); | 570 weak_ptr_factory_.GetWeakPtr(), info.id))); |
| 570 | 571 |
| 571 icon_url_fetcher->SetLoadFlags( | 572 icon_url_fetcher->SetLoadFlags( |
| 572 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); | 573 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); |
| 573 icon_url_fetcher->SetRequestContext( | 574 icon_url_fetcher->SetRequestContext( |
| 574 wrapper_->profile()->GetRequestContext()); | 575 tab_contents_->profile()->GetRequestContext()); |
| 575 icon_url_fetcher->Start(); | 576 icon_url_fetcher->Start(); |
| 576 } | 577 } |
| 577 | 578 |
| 578 AsyncOperationFinished(); | 579 AsyncOperationFinished(); |
| 579 } | 580 } |
| 580 | 581 |
| 581 void WebIntentPickerController::OnExtensionIconURLFetchComplete( | 582 void WebIntentPickerController::OnExtensionIconURLFetchComplete( |
| 582 const string16& extension_id, const net::URLFetcher* source) { | 583 const string16& extension_id, const net::URLFetcher* source) { |
| 583 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 584 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 584 if (source->GetResponseCode() != 200) { | 585 if (source->GetResponseCode() != 200) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 681 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 681 if (--pending_async_count_ == 0) { | 682 if (--pending_async_count_ == 0) { |
| 682 if (picker_) | 683 if (picker_) |
| 683 picker_->OnPendingAsyncCompleted(); | 684 picker_->OnPendingAsyncCompleted(); |
| 684 } | 685 } |
| 685 } | 686 } |
| 686 | 687 |
| 687 void WebIntentPickerController::CreatePicker() { | 688 void WebIntentPickerController::CreatePicker() { |
| 688 // If picker is non-NULL, it was set by a test. | 689 // If picker is non-NULL, it was set by a test. |
| 689 if (picker_ == NULL) | 690 if (picker_ == NULL) |
| 690 picker_ = WebIntentPicker::Create(wrapper_, this, picker_model_.get()); | 691 picker_ = WebIntentPicker::Create(tab_contents_, this, picker_model_.get()); |
| 691 picker_shown_ = true; | 692 picker_shown_ = true; |
| 692 } | 693 } |
| 693 | 694 |
| 694 void WebIntentPickerController::ClosePicker() { | 695 void WebIntentPickerController::ClosePicker() { |
| 695 if (picker_) | 696 if (picker_) |
| 696 picker_->Close(); | 697 picker_->Close(); |
| 697 } | 698 } |
| OLD | NEW |