Broke ContentSettingBubbleModelTest.Plugins on Android.
[chromium-blink-merge.git] / content / browser / intents / internal_web_intents_dispatcher.cc
blob3cc0e464ebba77ba66401a4c31b5371558c0eca5
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.
5 #include "content/browser/intents/internal_web_intents_dispatcher.h"
7 #include "content/browser/intents/intent_injector.h"
8 #include "webkit/glue/web_intent_data.h"
9 #include "webkit/glue/web_intent_reply_data.h"
11 namespace content {
13 InternalWebIntentsDispatcher::InternalWebIntentsDispatcher(
14 const webkit_glue::WebIntentData& intent)
15 : intent_(intent),
16 intent_injector_(NULL) {}
18 InternalWebIntentsDispatcher::InternalWebIntentsDispatcher(
19 const webkit_glue::WebIntentData& intent,
20 const ReplyCallback& reply_callback)
21 : intent_(intent),
22 intent_injector_(NULL),
23 reply_callback_(reply_callback) {}
25 InternalWebIntentsDispatcher::~InternalWebIntentsDispatcher() {}
27 const webkit_glue::WebIntentData& InternalWebIntentsDispatcher::GetIntent() {
28 return intent_;
31 void InternalWebIntentsDispatcher::DispatchIntent(
32 WebContents* destination_contents) {
33 DCHECK(destination_contents);
34 DCHECK(!intent_injector_);
35 intent_injector_ = new IntentInjector(destination_contents);
36 intent_injector_->SetIntent(this, intent_);
39 void InternalWebIntentsDispatcher::ResetDispatch() {
40 if (intent_injector_) {
41 intent_injector_->Abandon();
42 intent_injector_ = NULL;
46 void InternalWebIntentsDispatcher::SendReply(
47 const webkit_glue::WebIntentReply& reply) {
48 intent_injector_ = NULL;
50 for (size_t i = 0; i < reply_notifiers_.size(); ++i) {
51 if (!reply_notifiers_[i].is_null())
52 reply_notifiers_[i].Run(reply.type);
55 // Notify the callback of the reply.
56 if (!reply_callback_.is_null())
57 reply_callback_.Run(reply);
59 delete this;
62 void InternalWebIntentsDispatcher::RegisterReplyNotification(
63 const WebIntentsDispatcher::ReplyNotification& closure) {
64 reply_notifiers_.push_back(closure);
67 } // namespace content