Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(692)

Side by Side Diff: content/renderer/web_intents_host.cc

Issue 9692017: An internal intents dispatcher useful for initiating an intent from the browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/renderer/web_intents_host.h" 5 #include "content/renderer/web_intents_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "content/common/intents_messages.h" 9 #include "content/common/intents_messages.h"
10 #include "content/renderer/render_view_impl.h" 10 #include "content/renderer/render_view_impl.h"
(...skipping 13 matching lines...) Expand all
24 using WebKit::WebIntentRequest; 24 using WebKit::WebIntentRequest;
25 using WebKit::WebString; 25 using WebKit::WebString;
26 using WebKit::WebSerializedScriptValue; 26 using WebKit::WebSerializedScriptValue;
27 27
28 // This class encapsulates the API the Intent object will expose to Javascript. 28 // This class encapsulates the API the Intent object will expose to Javascript.
29 // It is made available to the Javascript runtime in the service page using 29 // It is made available to the Javascript runtime in the service page using
30 // NPAPI methods as with plugin/Javascript interaction objects and other 30 // NPAPI methods as with plugin/Javascript interaction objects and other
31 // browser-provided Javascript API objects on |window|. 31 // browser-provided Javascript API objects on |window|.
32 class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass { 32 class WebIntentsHost::BoundDeliveredIntent : public CppBoundClass {
33 public: 33 public:
34 BoundDeliveredIntent(const string16& action, 34 BoundDeliveredIntent(const webkit_glue::WebIntentData& intent,
35 const string16& type,
36 const string16& data,
37 WebIntentsHost* parent, 35 WebIntentsHost* parent,
38 WebFrame* frame) { 36 WebFrame* frame) {
39 action_ = WebString(action).utf8(); 37 action_ = WebString(intent.action).utf8();
40 type_ = WebString(type).utf8(); 38 type_ = WebString(intent.type).utf8();
41 parent_ = parent; 39 parent_ = parent;
42 40
43 v8::HandleScope scope; 41 v8::HandleScope scope;
44 v8::Local<v8::Context> ctx = frame->mainWorldScriptContext(); 42 v8::Local<v8::Context> ctx = frame->mainWorldScriptContext();
45 v8::Context::Scope cscope(ctx); 43 v8::Context::Scope cscope(ctx);
46 WebSerializedScriptValue ssv = 44 v8::Local<v8::Value> data_obj;
47 WebSerializedScriptValue::fromString(WebString(data)); 45
48 // TODO(gbillock): use an exception handler instead? Need to 46 if (intent.data_type == webkit_glue::WebIntentData::SERIALIZED) {
49 // pass back error state to caller? This is a pretty unexpected 47 WebSerializedScriptValue ssv =
50 // internal error... 48 WebSerializedScriptValue::fromString(WebString(intent.data));
51 CHECK(!ssv.isNull()); 49 // TODO(gbillock): use an exception handler instead? Need to
52 v8::Local<v8::Value> data_obj = 50 // pass back error state to caller? This is a pretty unexpected
53 v8::Local<v8::Value>::New(ssv.deserialize()); 51 // internal error...
52 CHECK(!ssv.isNull());
James Hawkins 2012/03/12 23:19:11 These should likely be DCHECKs.
Greg Billock 2012/03/12 23:52:22 We're parsing something we ourselves serialized. I
James Hawkins 2012/03/13 00:59:02 DCHECK vs CHECK is not about severity. CHECK shou
Greg Billock 2012/03/13 17:42:38 DCHECK here will immediately mean a harder-to-diag
James Hawkins 2012/03/13 18:22:03 How is that? They're the exact same except DCHECK
Greg Billock 2012/03/13 19:26:50 If control continues when ssv.isNull, ssv.deserial
53 data_obj = v8::Local<v8::Value>::New(ssv.deserialize());
54 } else {
55 CHECK(intent.data_type == webkit_glue::WebIntentData::UNSERIALIZED);
56 data_obj = v8::String::New(intent.unserialized_data.data(),
57 intent.unserialized_data.length());
58 }
54 59
55 data_val_.reset(new CppVariant); 60 data_val_.reset(new CppVariant);
56 WebBindings::toNPVariant(data_obj, frame->windowObject(), data_val_.get()); 61 WebBindings::toNPVariant(data_obj, frame->windowObject(), data_val_.get());
57 62
58 BindGetterCallback("action", base::Bind(&BoundDeliveredIntent::getAction, 63 BindGetterCallback("action", base::Bind(&BoundDeliveredIntent::getAction,
59 base::Unretained(this))); 64 base::Unretained(this)));
60 BindGetterCallback("type", base::Bind(&BoundDeliveredIntent::getType, 65 BindGetterCallback("type", base::Bind(&BoundDeliveredIntent::getType,
61 base::Unretained(this))); 66 base::Unretained(this)));
62 BindGetterCallback("data", base::Bind(&BoundDeliveredIntent::getData, 67 BindGetterCallback("data", base::Bind(&BoundDeliveredIntent::getData,
63 base::Unretained(this))); 68 base::Unretained(this)));
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 } 193 }
189 194
190 // We set the intent payload into all top-level frame window objects. This 195 // We set the intent payload into all top-level frame window objects. This
191 // should persist the data through redirects, and not deliver it to any 196 // should persist the data through redirects, and not deliver it to any
192 // sub-frames. TODO(gbillock): This policy needs to be fine-tuned and 197 // sub-frames. TODO(gbillock): This policy needs to be fine-tuned and
193 // documented. 198 // documented.
194 void WebIntentsHost::DidClearWindowObject(WebFrame* frame) { 199 void WebIntentsHost::DidClearWindowObject(WebFrame* frame) {
195 if (intent_.get() == NULL || frame->top() != frame) 200 if (intent_.get() == NULL || frame->top() != frame)
196 return; 201 return;
197 202
198 delivered_intent_.reset(new BoundDeliveredIntent( 203 delivered_intent_.reset(
199 intent_->action, intent_->type, intent_->data, this, frame)); 204 new BoundDeliveredIntent(*(intent_.get()), this, frame));
200 delivered_intent_->BindToJavascript(frame, "intent"); 205 delivered_intent_->BindToJavascript(frame, "intent");
201 } 206 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698