| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/intents/web_intents_dispatcher_impl.h" | |
| 6 | |
| 7 #include "content/browser/intents/intent_injector.h" | |
| 8 #include "content/browser/intents/internal_web_intents_dispatcher.h" | |
| 9 #include "content/browser/web_contents/web_contents_impl.h" | |
| 10 #include "content/common/intents_messages.h" | |
| 11 #include "webkit/glue/web_intent_data.h" | |
| 12 #include "webkit/glue/web_intent_reply_data.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 WebIntentsDispatcher* WebIntentsDispatcher::Create( | |
| 17 const webkit_glue::WebIntentData& data) { | |
| 18 return new InternalWebIntentsDispatcher(data); | |
| 19 } | |
| 20 | |
| 21 WebIntentsDispatcherImpl::WebIntentsDispatcherImpl( | |
| 22 WebContents* source_contents, | |
| 23 const webkit_glue::WebIntentData& intent, | |
| 24 int intent_id) | |
| 25 : WebContentsObserver(source_contents), | |
| 26 intent_(intent), | |
| 27 intent_id_(intent_id), | |
| 28 intent_injector_(NULL) { | |
| 29 // Ensure that WebIntentData sent from a renderer process | |
| 30 // carries the right payload type and no extraneous data. | |
| 31 intent_.blob_file = base::FilePath(); | |
| 32 intent_.blob_length = 0; | |
| 33 intent_.root_name = ""; | |
| 34 intent_.filesystem_id = ""; | |
| 35 intent_.data_type = webkit_glue::WebIntentData::SERIALIZED; | |
| 36 } | |
| 37 | |
| 38 WebIntentsDispatcherImpl::~WebIntentsDispatcherImpl() {} | |
| 39 | |
| 40 const webkit_glue::WebIntentData& WebIntentsDispatcherImpl::GetIntent() { | |
| 41 return intent_; | |
| 42 } | |
| 43 | |
| 44 void WebIntentsDispatcherImpl::DispatchIntent( | |
| 45 WebContents* destination_contents) { | |
| 46 DCHECK(!intent_injector_); | |
| 47 intent_injector_ = new IntentInjector(destination_contents); | |
| 48 intent_injector_->SetIntent(this, intent_); | |
| 49 } | |
| 50 | |
| 51 void WebIntentsDispatcherImpl::ResetDispatch() { | |
| 52 if (intent_injector_) { | |
| 53 intent_injector_->Abandon(); | |
| 54 intent_injector_ = NULL; | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 void WebIntentsDispatcherImpl::SendReply( | |
| 59 const webkit_glue::WebIntentReply& reply) { | |
| 60 intent_injector_ = NULL; | |
| 61 | |
| 62 // If this intent is attached to a WebContents, we dispatch the request back | |
| 63 // to the renderer. Browser process initiated intents are not | |
| 64 // associated with a WebContents. | |
| 65 if (web_contents()) { | |
| 66 Send(new IntentsMsg_WebIntentReply( | |
| 67 routing_id(), reply, intent_id_)); | |
| 68 } | |
| 69 | |
| 70 for (size_t i = 0; i < reply_notifiers_.size(); ++i) { | |
| 71 if (!reply_notifiers_[i].is_null()) | |
| 72 reply_notifiers_[i].Run(reply.type); | |
| 73 } | |
| 74 | |
| 75 delete this; | |
| 76 } | |
| 77 | |
| 78 void WebIntentsDispatcherImpl::RegisterReplyNotification( | |
| 79 const WebIntentsDispatcher::ReplyNotification& closure) { | |
| 80 reply_notifiers_.push_back(closure); | |
| 81 } | |
| 82 | |
| 83 void WebIntentsDispatcherImpl::WebContentsDestroyed(WebContents* contents) { | |
| 84 if (intent_injector_) | |
| 85 intent_injector_->SourceWebContentsDestroyed(contents); | |
| 86 | |
| 87 intent_injector_ = NULL; | |
| 88 } | |
| 89 | |
| 90 } // namespace content | |
| OLD | NEW |