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/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 Loading... | |
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 DCHECK(!ssv.isNull()); |
52 v8::Local<v8::Value> data_obj = | 50 data_obj = v8::Local<v8::Value>::New(ssv.deserialize()); |
53 v8::Local<v8::Value>::New(ssv.deserialize()); | 51 } else { |
52 CHECK(intent.data_type == webkit_glue::WebIntentData::UNSERIALIZED); | |
James Hawkins
2012/03/13 20:15:44
DCHECK
Greg Billock
2012/03/13 20:34:42
Done.
| |
53 data_obj = v8::String::New(intent.unserialized_data.data(), | |
54 intent.unserialized_data.length()); | |
55 } | |
54 | 56 |
55 data_val_.reset(new CppVariant); | 57 data_val_.reset(new CppVariant); |
56 WebBindings::toNPVariant(data_obj, frame->windowObject(), data_val_.get()); | 58 WebBindings::toNPVariant(data_obj, frame->windowObject(), data_val_.get()); |
57 | 59 |
58 BindGetterCallback("action", base::Bind(&BoundDeliveredIntent::getAction, | 60 BindGetterCallback("action", base::Bind(&BoundDeliveredIntent::getAction, |
59 base::Unretained(this))); | 61 base::Unretained(this))); |
60 BindGetterCallback("type", base::Bind(&BoundDeliveredIntent::getType, | 62 BindGetterCallback("type", base::Bind(&BoundDeliveredIntent::getType, |
61 base::Unretained(this))); | 63 base::Unretained(this))); |
62 BindGetterCallback("data", base::Bind(&BoundDeliveredIntent::getData, | 64 BindGetterCallback("data", base::Bind(&BoundDeliveredIntent::getData, |
63 base::Unretained(this))); | 65 base::Unretained(this))); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 } | 190 } |
189 | 191 |
190 // We set the intent payload into all top-level frame window objects. This | 192 // 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 | 193 // 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 | 194 // sub-frames. TODO(gbillock): This policy needs to be fine-tuned and |
193 // documented. | 195 // documented. |
194 void WebIntentsHost::DidClearWindowObject(WebFrame* frame) { | 196 void WebIntentsHost::DidClearWindowObject(WebFrame* frame) { |
195 if (intent_.get() == NULL || frame->top() != frame) | 197 if (intent_.get() == NULL || frame->top() != frame) |
196 return; | 198 return; |
197 | 199 |
198 delivered_intent_.reset(new BoundDeliveredIntent( | 200 delivered_intent_.reset( |
199 intent_->action, intent_->type, intent_->data, this, frame)); | 201 new BoundDeliveredIntent(*(intent_.get()), this, frame)); |
200 delivered_intent_->BindToJavascript(frame, "intent"); | 202 delivered_intent_->BindToJavascript(frame, "intent"); |
201 } | 203 } |
OLD | NEW |