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/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 "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/favicon/favicon_service.h" | 12 #include "chrome/browser/favicon/favicon_service.h" |
13 #include "chrome/browser/intents/web_intents_registry.h" | 13 #include "chrome/browser/intents/web_intents_registry.h" |
14 #include "chrome/browser/intents/web_intents_registry_factory.h" | 14 #include "chrome/browser/intents/web_intents_registry_factory.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/tabs/tab_strip_model.h" |
16 #include "chrome/browser/ui/browser_navigator.h" | 17 #include "chrome/browser/ui/browser_navigator.h" |
17 #include "chrome/browser/ui/intents/web_intent_picker.h" | 18 #include "chrome/browser/ui/intents/web_intent_picker.h" |
18 #include "chrome/browser/ui/intents/web_intent_picker_factory.h" | 19 #include "chrome/browser/ui/intents/web_intent_picker_factory.h" |
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
20 #include "chrome/browser/webdata/web_data_service.h" | 21 #include "chrome/browser/webdata/web_data_service.h" |
21 #include "content/browser/intents/intent_injector.h" | 22 #include "content/browser/intents/intent_injector.h" |
22 #include "content/browser/tab_contents/tab_contents.h" | 23 #include "content/browser/tab_contents/tab_contents.h" |
23 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
24 #include "ui/gfx/codec/png_codec.h" | 25 #include "ui/gfx/codec/png_codec.h" |
25 #include "webkit/glue/web_intent_service_data.h" | 26 #include "webkit/glue/web_intent_service_data.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 : wrapper_(wrapper), | 108 : wrapper_(wrapper), |
108 picker_factory_(factory), | 109 picker_factory_(factory), |
109 web_intent_data_fetcher_( | 110 web_intent_data_fetcher_( |
110 new WebIntentDataFetcher(this, | 111 new WebIntentDataFetcher(this, |
111 GetWebIntentsRegistry(wrapper))), | 112 GetWebIntentsRegistry(wrapper))), |
112 favicon_fetcher_( | 113 favicon_fetcher_( |
113 new FaviconFetcher(this, GetFaviconService(wrapper))), | 114 new FaviconFetcher(this, GetFaviconService(wrapper))), |
114 picker_(NULL), | 115 picker_(NULL), |
115 pending_async_count_(0), | 116 pending_async_count_(0), |
116 routing_id_(0), | 117 routing_id_(0), |
117 intent_id_(0) { | 118 intent_id_(0), |
| 119 service_tab_(NULL) { |
118 NavigationController* controller = &wrapper->controller(); | 120 NavigationController* controller = &wrapper->controller(); |
119 registrar_.Add(this, content::NOTIFICATION_LOAD_START, | 121 registrar_.Add(this, content::NOTIFICATION_LOAD_START, |
120 content::Source<NavigationController>(controller)); | 122 content::Source<NavigationController>(controller)); |
121 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSING, | 123 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSING, |
122 content::Source<NavigationController>(controller)); | 124 content::Source<NavigationController>(controller)); |
123 } | 125 } |
124 | 126 |
125 WebIntentPickerController::~WebIntentPickerController() { | 127 WebIntentPickerController::~WebIntentPickerController() { |
126 } | 128 } |
127 | 129 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 int routing_id) | 171 int routing_id) |
170 : TabContentsObserver(wrapper->tab_contents()), | 172 : TabContentsObserver(wrapper->tab_contents()), |
171 wrapper_(wrapper), | 173 wrapper_(wrapper), |
172 intent_injector_(injector), | 174 intent_injector_(injector), |
173 routing_id_(routing_id) {} | 175 routing_id_(routing_id) {} |
174 virtual ~InvokingTabObserver() {} | 176 virtual ~InvokingTabObserver() {} |
175 | 177 |
176 virtual void TabContentsDestroyed(TabContents* tab) OVERRIDE { | 178 virtual void TabContentsDestroyed(TabContents* tab) OVERRIDE { |
177 if (intent_injector_) | 179 if (intent_injector_) |
178 intent_injector_->SourceTabContentsDestroyed(tab); | 180 intent_injector_->SourceTabContentsDestroyed(tab); |
| 181 wrapper_ = NULL; |
179 } | 182 } |
180 | 183 |
181 virtual bool Send(IPC::Message* message) OVERRIDE { | 184 virtual bool Send(IPC::Message* message) OVERRIDE { |
182 // The injector can return exactly one message. After that we don't talk | 185 // The injector can return exactly one message. After that we don't talk |
183 // to it again, since it may have deleted itself. | 186 // to it again, since it may have deleted itself. |
184 intent_injector_ = NULL; | 187 intent_injector_ = NULL; |
185 | 188 |
| 189 if (!wrapper_) |
| 190 return false; |
| 191 |
| 192 MessageLoopForUI::current()->PostTask( |
| 193 FROM_HERE, |
| 194 base::Bind(&WebIntentPickerController::OnSendReturnMessage, |
| 195 base::Unretained(wrapper_->web_intent_picker_controller()))); |
| 196 |
186 message->set_routing_id(routing_id_); | 197 message->set_routing_id(routing_id_); |
187 return wrapper_->Send(message); | 198 return wrapper_->Send(message); |
188 } | 199 } |
189 | 200 |
190 private: | 201 private: |
191 // Weak pointer to the source tab invoking the intent. | 202 // Weak pointer to the source tab invoking the intent. |
192 TabContentsWrapper* wrapper_; | 203 TabContentsWrapper* wrapper_; |
193 | 204 |
194 // Weak pointer to the intent injector managing delivering the intent data to | 205 // Weak pointer to the intent injector managing delivering the intent data to |
195 // the service tab. | 206 // the service tab. |
(...skipping 18 matching lines...) Expand all Loading... |
214 // during the lifetime of the service url context, and that may mean we | 225 // during the lifetime of the service url context, and that may mean we |
215 // need to pass more information into the injector to find the picker again | 226 // need to pass more information into the injector to find the picker again |
216 // and close it. Also: the above conditional construction is just because | 227 // and close it. Also: the above conditional construction is just because |
217 // there isn't Mac/Win support yet. When that's there, it'll be an else. | 228 // there isn't Mac/Win support yet. When that's there, it'll be an else. |
218 browser::NavigateParams params(NULL, urls_[index], | 229 browser::NavigateParams params(NULL, urls_[index], |
219 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 230 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
220 params.disposition = NEW_FOREGROUND_TAB; | 231 params.disposition = NEW_FOREGROUND_TAB; |
221 params.profile = wrapper_->profile(); | 232 params.profile = wrapper_->profile(); |
222 browser::Navigate(¶ms); | 233 browser::Navigate(¶ms); |
223 new_tab_contents = params.target_contents->tab_contents(); | 234 new_tab_contents = params.target_contents->tab_contents(); |
| 235 service_tab_ = new_tab_contents; |
224 | 236 |
225 ClosePicker(); | 237 ClosePicker(); |
226 } | 238 } |
227 | 239 |
228 IntentInjector* injector = new IntentInjector(new_tab_contents); | 240 IntentInjector* injector = new IntentInjector(new_tab_contents); |
229 injector->SetIntent(new InvokingTabObserver(wrapper_, injector, routing_id_), | 241 injector->SetIntent(new InvokingTabObserver(wrapper_, injector, routing_id_), |
230 intent_, | 242 intent_, |
231 intent_id_); | 243 intent_id_); |
232 } | 244 } |
233 | 245 |
234 void WebIntentPickerController::OnCancelled() { | 246 void WebIntentPickerController::OnCancelled() { |
235 InvokingTabObserver forwarder(wrapper_, NULL, routing_id_); | 247 InvokingTabObserver forwarder(wrapper_, NULL, routing_id_); |
236 forwarder.Send(new IntentsMsg_WebIntentReply( | 248 if (service_tab_) { |
237 0, webkit_glue::WEB_INTENT_PICKER_CANCELLED, string16(), intent_id_)); | 249 forwarder.Send(new IntentsMsg_WebIntentReply( |
| 250 0, webkit_glue::WEB_INTENT_SERVICE_TAB_CLOSED, string16(), intent_id_)); |
| 251 } else { |
| 252 forwarder.Send(new IntentsMsg_WebIntentReply( |
| 253 0, webkit_glue::WEB_INTENT_PICKER_CANCELLED, string16(), intent_id_)); |
| 254 } |
| 255 |
| 256 ClosePicker(); |
238 } | 257 } |
239 | 258 |
240 void WebIntentPickerController::OnClosing() { | 259 void WebIntentPickerController::OnClosing() { |
| 260 } |
| 261 |
| 262 void WebIntentPickerController::OnSendReturnMessage() { |
241 ClosePicker(); | 263 ClosePicker(); |
| 264 |
| 265 if (service_tab_) { |
| 266 int index = TabStripModel::kNoTab; |
| 267 Browser* browser = Browser::GetBrowserForController( |
| 268 &service_tab_->controller(), &index); |
| 269 if (browser) { |
| 270 browser->tabstrip_model()->CloseTabContentsAt( |
| 271 index, TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); |
| 272 } |
| 273 service_tab_ = NULL; |
| 274 } |
242 } | 275 } |
243 | 276 |
244 void WebIntentPickerController::OnWebIntentDataAvailable( | 277 void WebIntentPickerController::OnWebIntentDataAvailable( |
245 const std::vector<webkit_glue::WebIntentServiceData>& services) { | 278 const std::vector<webkit_glue::WebIntentServiceData>& services) { |
246 urls_.clear(); | 279 urls_.clear(); |
247 for (size_t i = 0; i < services.size(); ++i) { | 280 for (size_t i = 0; i < services.size(); ++i) { |
248 urls_.push_back(services[i].service_url); | 281 urls_.push_back(services[i].service_url); |
249 } | 282 } |
250 service_data_ = services; | 283 service_data_ = services; |
251 | 284 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 if (gfx::PNGCodec::Decode(favicon_data.image_data->front(), | 375 if (gfx::PNGCodec::Decode(favicon_data.image_data->front(), |
343 favicon_data.image_data->size(), | 376 favicon_data.image_data->size(), |
344 &icon_bitmap)) { | 377 &icon_bitmap)) { |
345 controller_->OnFaviconDataAvailable(index, icon_bitmap); | 378 controller_->OnFaviconDataAvailable(index, icon_bitmap); |
346 return; | 379 return; |
347 } | 380 } |
348 } | 381 } |
349 | 382 |
350 controller_->OnFaviconDataUnavailable(index); | 383 controller_->OnFaviconDataUnavailable(index); |
351 } | 384 } |
OLD | NEW |