| 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 "content/browser/intents/intent_injector.h" | 5 #include "content/browser/intents/intent_injector.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "content/browser/child_process_security_policy_impl.h" | 12 #include "content/browser/child_process_security_policy_impl.h" |
| 13 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 14 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
| 15 #include "content/common/intents_messages.h" | 15 #include "content/common/intents_messages.h" |
| 16 #include "content/public/browser/web_intents_dispatcher.h" | 16 #include "content/public/browser/web_intents_dispatcher.h" |
| 17 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 18 #include "webkit/glue/web_intent_data.h" | 18 #include "webkit/glue/web_intent_data.h" |
| 19 #include "webkit/glue/web_intent_reply_data.h" | 19 #include "webkit/glue/web_intent_reply_data.h" |
| 20 | 20 |
| 21 using content::RenderViewHost; | 21 using content::RenderViewHost; |
| 22 using content::WebContents; | 22 using content::WebContents; |
| 23 | 23 |
| 24 IntentInjector::IntentInjector(WebContents* web_contents) | 24 IntentInjector::IntentInjector(WebContents* web_contents) |
| 25 : content::WebContentsObserver(web_contents), | 25 : content::WebContentsObserver(web_contents), |
| 26 intents_dispatcher_(NULL) { | 26 intents_dispatcher_(NULL), |
| 27 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 27 DCHECK(web_contents); | 28 DCHECK(web_contents); |
| 28 } | 29 } |
| 29 | 30 |
| 30 IntentInjector::~IntentInjector() { | 31 IntentInjector::~IntentInjector() { |
| 31 } | 32 } |
| 32 | 33 |
| 33 void IntentInjector::WebContentsDestroyed(content::WebContents* contents) { | 34 void IntentInjector::WebContentsDestroyed(content::WebContents* contents) { |
| 34 if (intents_dispatcher_) { | 35 if (intents_dispatcher_) { |
| 35 intents_dispatcher_->SendReplyMessage( | 36 intents_dispatcher_->SendReplyMessage( |
| 36 webkit_glue::WEB_INTENT_SERVICE_CONTENTS_CLOSED, string16()); | 37 webkit_glue::WEB_INTENT_SERVICE_CONTENTS_CLOSED, string16()); |
| 37 } | 38 } |
| 38 | 39 |
| 39 delete this; | 40 delete this; |
| 40 } | 41 } |
| 41 | 42 |
| 42 void IntentInjector::SourceWebContentsDestroyed(WebContents* contents) { | 43 void IntentInjector::SourceWebContentsDestroyed(WebContents* contents) { |
| 43 intents_dispatcher_ = NULL; | 44 intents_dispatcher_ = NULL; |
| 44 } | 45 } |
| 45 | 46 |
| 46 void IntentInjector::SetIntent( | 47 void IntentInjector::SetIntent( |
| 47 content::WebIntentsDispatcher* intents_dispatcher, | 48 content::WebIntentsDispatcher* intents_dispatcher, |
| 48 const webkit_glue::WebIntentData& intent) { | 49 const webkit_glue::WebIntentData& intent) { |
| 49 intents_dispatcher_ = intents_dispatcher; | 50 intents_dispatcher_ = intents_dispatcher; |
| 50 intents_dispatcher_->RegisterReplyNotification( | 51 intents_dispatcher_->RegisterReplyNotification( |
| 51 base::Bind(&IntentInjector::OnSendReturnMessage, base::Unretained(this))); | 52 base::Bind(&IntentInjector::OnSendReturnMessage, |
| 53 weak_factory_.GetWeakPtr())); |
| 52 source_intent_.reset(new webkit_glue::WebIntentData(intent)); | 54 source_intent_.reset(new webkit_glue::WebIntentData(intent)); |
| 53 initial_url_ = web_contents()->GetPendingSiteInstance()->GetSite(); | 55 initial_url_ = web_contents()->GetPendingSiteInstance()->GetSite(); |
| 54 } | 56 } |
| 55 | 57 |
| 58 void IntentInjector::Abandon() { |
| 59 intents_dispatcher_ = NULL; |
| 60 delete this; |
| 61 } |
| 62 |
| 56 void IntentInjector::OnSendReturnMessage( | 63 void IntentInjector::OnSendReturnMessage( |
| 57 webkit_glue::WebIntentReplyType reply_type) { | 64 webkit_glue::WebIntentReplyType reply_type) { |
| 58 intents_dispatcher_ = NULL; | 65 intents_dispatcher_ = NULL; |
| 59 } | 66 } |
| 60 | 67 |
| 61 void IntentInjector::RenderViewCreated(RenderViewHost* render_view_host) { | 68 void IntentInjector::RenderViewCreated(RenderViewHost* render_view_host) { |
| 62 if (source_intent_.get() == NULL || | 69 if (source_intent_.get() == NULL || |
| 63 CommandLine::ForCurrentProcess()->HasSwitch( | 70 CommandLine::ForCurrentProcess()->HasSwitch( |
| 64 switches::kDisableWebIntents) || | 71 switches::kDisableWebIntents) || |
| 65 web_contents()->GetRenderViewHost() == NULL) { | 72 web_contents()->GetRenderViewHost() == NULL) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableWebIntents)) | 105 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableWebIntents)) |
| 99 NOTREACHED(); | 106 NOTREACHED(); |
| 100 | 107 |
| 101 if (intents_dispatcher_) { | 108 if (intents_dispatcher_) { |
| 102 // Ensure we only call SendReplyMessage once. | 109 // Ensure we only call SendReplyMessage once. |
| 103 content::WebIntentsDispatcher* intents_dispatcher = intents_dispatcher_; | 110 content::WebIntentsDispatcher* intents_dispatcher = intents_dispatcher_; |
| 104 intents_dispatcher_ = NULL; | 111 intents_dispatcher_ = NULL; |
| 105 intents_dispatcher->SendReplyMessage(reply_type, data); | 112 intents_dispatcher->SendReplyMessage(reply_type, data); |
| 106 } | 113 } |
| 107 } | 114 } |
| OLD | NEW |