| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/renderer/extensions/document_custom_bindings.h" | 5 #include "chrome/renderer/extensions/document_custom_bindings.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "chrome/common/extensions/extension.h" |
| 10 #include "chrome/renderer/extensions/chrome_v8_context.h" | 11 #include "chrome/renderer/extensions/chrome_v8_context.h" |
| 11 #include "third_party/WebKit/public/web/WebDocument.h" | 12 #include "third_party/WebKit/public/web/WebDocument.h" |
| 12 #include "third_party/WebKit/public/web/WebFrame.h" | 13 #include "third_party/WebKit/public/web/WebFrame.h" |
| 13 #include "v8/include/v8.h" | 14 #include "v8/include/v8.h" |
| 14 | 15 |
| 15 namespace extensions { | 16 namespace extensions { |
| 16 | 17 |
| 17 DocumentCustomBindings::DocumentCustomBindings( | 18 DocumentCustomBindings::DocumentCustomBindings( |
| 18 Dispatcher* dispatcher, ChromeV8Context* context) | 19 Dispatcher* dispatcher, ChromeV8Context* context) |
| 19 : ChromeV8Extension(dispatcher, context) { | 20 : ChromeV8Extension(dispatcher, context) { |
| 20 RouteFunction("RegisterElement", | 21 RouteFunction("RegisterElement", |
| 21 base::Bind(&DocumentCustomBindings::RegisterElement, | 22 base::Bind(&DocumentCustomBindings::RegisterElement, |
| 22 base::Unretained(this))); | 23 base::Unretained(this))); |
| 24 RouteFunction("CompareURLs", |
| 25 base::Bind(&DocumentCustomBindings::CompareURLs, |
| 26 base::Unretained(this))); |
| 27 } |
| 28 |
| 29 void DocumentCustomBindings::CompareURLs( |
| 30 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 31 if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsString()) { |
| 32 NOTREACHED(); |
| 33 return; |
| 34 } |
| 35 |
| 36 GURL default_url(context()->extension()->url()); |
| 37 |
| 38 std::string url1_str(*v8::String::AsciiValue(args[0])); |
| 39 std::string url2_str(*v8::String::AsciiValue(args[1])); |
| 40 |
| 41 GURL resolved_url1(default_url.Resolve(url1_str)); |
| 42 GURL resolved_url2(default_url.Resolve(url2_str)); |
| 43 |
| 44 args.GetReturnValue().Set(v8::Boolean::New(resolved_url1 == resolved_url2)); |
| 23 } | 45 } |
| 24 | 46 |
| 25 // Attach an event name to an object. | 47 // Attach an event name to an object. |
| 26 void DocumentCustomBindings::RegisterElement( | 48 void DocumentCustomBindings::RegisterElement( |
| 27 const v8::FunctionCallbackInfo<v8::Value>& args) { | 49 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 28 if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsObject()) { | 50 if (args.Length() != 2 || !args[0]->IsString() || !args[1]->IsObject()) { |
| 29 NOTREACHED(); | 51 NOTREACHED(); |
| 30 return; | 52 return; |
| 31 } | 53 } |
| 32 | 54 |
| 33 std::string element_name(*v8::String::AsciiValue(args[0])); | 55 std::string element_name(*v8::String::AsciiValue(args[0])); |
| 34 v8::Local<v8::Object> options = args[1]->ToObject(); | 56 v8::Local<v8::Object> options = args[1]->ToObject(); |
| 35 | 57 |
| 36 WebKit::WebExceptionCode ec = 0; | 58 WebKit::WebExceptionCode ec = 0; |
| 37 WebKit::WebDocument document = context()->web_frame()->document(); | 59 WebKit::WebDocument document = context()->web_frame()->document(); |
| 38 v8::Handle<v8::Value> constructor = | 60 v8::Handle<v8::Value> constructor = |
| 39 document.registerEmbedderCustomElement( | 61 document.registerEmbedderCustomElement( |
| 40 WebKit::WebString::fromUTF8(element_name), options, ec); | 62 WebKit::WebString::fromUTF8(element_name), options, ec); |
| 41 args.GetReturnValue().Set(constructor); | 63 args.GetReturnValue().Set(constructor); |
| 42 } | 64 } |
| 43 | 65 |
| 44 } // namespace extensions | 66 } // namespace extensions |
| OLD | NEW |