| 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 "chrome/renderer/extensions/dispatcher.h" |     5 #include "chrome/renderer/extensions/dispatcher.h" | 
|     6  |     6  | 
|     7 #include "base/callback.h" |     7 #include "base/callback.h" | 
|     8 #include "base/command_line.h" |     8 #include "base/command_line.h" | 
|     9 #include "base/debug/alias.h" |     9 #include "base/debug/alias.h" | 
|    10 #include "base/json/json_reader.h" |    10 #include "base/json/json_reader.h" | 
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   221                    base::Unretained(this))); |   221                    base::Unretained(this))); | 
|   222     RouteFunction("GetModuleSystem", |   222     RouteFunction("GetModuleSystem", | 
|   223         base::Bind(&V8ContextNativeHandler::GetModuleSystem, |   223         base::Bind(&V8ContextNativeHandler::GetModuleSystem, | 
|   224                    base::Unretained(this))); |   224                    base::Unretained(this))); | 
|   225   } |   225   } | 
|   226  |   226  | 
|   227  private: |   227  private: | 
|   228   void GetAvailability(const v8::FunctionCallbackInfo<v8::Value>& args) { |   228   void GetAvailability(const v8::FunctionCallbackInfo<v8::Value>& args) { | 
|   229     CHECK_EQ(args.Length(), 1); |   229     CHECK_EQ(args.Length(), 1); | 
|   230     v8::Isolate* isolate = args.GetIsolate(); |   230     v8::Isolate* isolate = args.GetIsolate(); | 
|   231     std::string api_name = *v8::String::AsciiValue(args[0]->ToString()); |   231     std::string api_name = *v8::String::Utf8Value(args[0]->ToString()); | 
|   232     Feature::Availability availability = context_->GetAvailability(api_name); |   232     Feature::Availability availability = context_->GetAvailability(api_name); | 
|   233  |   233  | 
|   234     v8::Handle<v8::Object> ret = v8::Object::New(); |   234     v8::Handle<v8::Object> ret = v8::Object::New(); | 
|   235     ret->Set(v8::String::NewFromUtf8(isolate, "is_available"), |   235     ret->Set(v8::String::NewFromUtf8(isolate, "is_available"), | 
|   236              v8::Boolean::New(isolate, availability.is_available())); |   236              v8::Boolean::New(isolate, availability.is_available())); | 
|   237     ret->Set(v8::String::NewFromUtf8(isolate, "message"), |   237     ret->Set(v8::String::NewFromUtf8(isolate, "message"), | 
|   238              v8::String::NewFromUtf8(isolate, availability.message().c_str())); |   238              v8::String::NewFromUtf8(isolate, availability.message().c_str())); | 
|   239     ret->Set(v8::String::NewFromUtf8(isolate, "result"), |   239     ret->Set(v8::String::NewFromUtf8(isolate, "result"), | 
|   240              v8::Integer::New(availability.result())); |   240              v8::Integer::New(availability.result())); | 
|   241     args.GetReturnValue().Set(ret); |   241     args.GetReturnValue().Set(ret); | 
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   394     if (send_request_disabled_) { |   394     if (send_request_disabled_) { | 
|   395       args.GetReturnValue().Set(v8::String::NewFromUtf8(args.GetIsolate(), |   395       args.GetReturnValue().Set(v8::String::NewFromUtf8(args.GetIsolate(), | 
|   396           "sendRequest and onRequest are obsolete." |   396           "sendRequest and onRequest are obsolete." | 
|   397           " Please use sendMessage and onMessage instead.")); |   397           " Please use sendMessage and onMessage instead.")); | 
|   398     } |   398     } | 
|   399   } |   399   } | 
|   400  |   400  | 
|   401   void HasSwitch(const v8::FunctionCallbackInfo<v8::Value>& args) { |   401   void HasSwitch(const v8::FunctionCallbackInfo<v8::Value>& args) { | 
|   402     CHECK(args.Length() == 1 && args[0]->IsString()); |   402     CHECK(args.Length() == 1 && args[0]->IsString()); | 
|   403     bool has_switch = CommandLine::ForCurrentProcess()->HasSwitch( |   403     bool has_switch = CommandLine::ForCurrentProcess()->HasSwitch( | 
|   404         *v8::String::AsciiValue(args[0])); |   404         *v8::String::Utf8Value(args[0])); | 
|   405     args.GetReturnValue().Set(v8::Boolean::New(args.GetIsolate(), has_switch)); |   405     args.GetReturnValue().Set(v8::Boolean::New(args.GetIsolate(), has_switch)); | 
|   406   } |   406   } | 
|   407  |   407  | 
|   408   std::string extension_id_; |   408   std::string extension_id_; | 
|   409   std::string context_type_; |   409   std::string context_type_; | 
|   410   bool is_incognito_context_; |   410   bool is_incognito_context_; | 
|   411   int manifest_version_; |   411   int manifest_version_; | 
|   412   bool send_request_disabled_; |   412   bool send_request_disabled_; | 
|   413 }; |   413 }; | 
|   414  |   414  | 
| (...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1561 } |  1561 } | 
|  1562  |  1562  | 
|  1563 bool Dispatcher::CheckContextAccessToExtensionAPI( |  1563 bool Dispatcher::CheckContextAccessToExtensionAPI( | 
|  1564     const std::string& function_name, ChromeV8Context* context) const { |  1564     const std::string& function_name, ChromeV8Context* context) const { | 
|  1565   if (!context) { |  1565   if (!context) { | 
|  1566     DLOG(ERROR) << "Not in a v8::Context"; |  1566     DLOG(ERROR) << "Not in a v8::Context"; | 
|  1567     return false; |  1567     return false; | 
|  1568   } |  1568   } | 
|  1569  |  1569  | 
|  1570   if (!context->extension()) { |  1570   if (!context->extension()) { | 
|  1571     v8::ThrowException(v8::Exception::Error( |  1571     context->isolate()->ThrowException(v8::Exception::Error( | 
|  1572         v8::String::NewFromUtf8(context->isolate(), "Not in an extension."))); |  1572         v8::String::NewFromUtf8(context->isolate(), "Not in an extension."))); | 
|  1573     return false; |  1573     return false; | 
|  1574   } |  1574   } | 
|  1575  |  1575  | 
|  1576   // Theoretically we could end up with bindings being injected into sandboxed |  1576   // Theoretically we could end up with bindings being injected into sandboxed | 
|  1577   // frames, for example content scripts. Don't let them execute API functions. |  1577   // frames, for example content scripts. Don't let them execute API functions. | 
|  1578   blink::WebFrame* frame = context->web_frame(); |  1578   blink::WebFrame* frame = context->web_frame(); | 
|  1579   if (IsSandboxedPage(UserScriptSlave::GetDataSourceURLForFrame(frame))) { |  1579   if (IsSandboxedPage(UserScriptSlave::GetDataSourceURLForFrame(frame))) { | 
|  1580     static const char kMessage[] = |  1580     static const char kMessage[] = | 
|  1581         "%s cannot be used within a sandboxed frame."; |  1581         "%s cannot be used within a sandboxed frame."; | 
|  1582     std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |  1582     std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); | 
|  1583     v8::ThrowException(v8::Exception::Error( |  1583     context->isolate()->ThrowException(v8::Exception::Error( | 
|  1584         v8::String::NewFromUtf8(context->isolate(), error_msg.c_str()))); |  1584         v8::String::NewFromUtf8(context->isolate(), error_msg.c_str()))); | 
|  1585     return false; |  1585     return false; | 
|  1586   } |  1586   } | 
|  1587  |  1587  | 
|  1588   Feature::Availability availability = context->GetAvailability(function_name); |  1588   Feature::Availability availability = context->GetAvailability(function_name); | 
|  1589   if (!availability.is_available()) { |  1589   if (!availability.is_available()) { | 
|  1590     v8::ThrowException(v8::Exception::Error(v8::String::NewFromUtf8( |  1590     context->isolate()->ThrowException( | 
|  1591         context->isolate(), availability.message().c_str()))); |  1591         v8::Exception::Error(v8::String::NewFromUtf8( | 
 |  1592             context->isolate(), availability.message().c_str()))); | 
|  1592   } |  1593   } | 
|  1593  |  1594  | 
|  1594   return availability.is_available(); |  1595   return availability.is_available(); | 
|  1595 } |  1596 } | 
|  1596  |  1597  | 
|  1597 void Dispatcher::DispatchEvent(const std::string& extension_id, |  1598 void Dispatcher::DispatchEvent(const std::string& extension_id, | 
|  1598                                const std::string& event_name) const { |  1599                                const std::string& event_name) const { | 
|  1599   base::ListValue args; |  1600   base::ListValue args; | 
|  1600   args.Set(0, new base::StringValue(event_name)); |  1601   args.Set(0, new base::StringValue(event_name)); | 
|  1601   args.Set(1, new base::ListValue()); |  1602   args.Set(1, new base::ListValue()); | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1643     RenderView* background_view = |  1644     RenderView* background_view = | 
|  1644         ExtensionHelper::GetBackgroundPage(extension_id); |  1645         ExtensionHelper::GetBackgroundPage(extension_id); | 
|  1645     if (background_view) { |  1646     if (background_view) { | 
|  1646       background_view->Send(new ExtensionHostMsg_EventAck( |  1647       background_view->Send(new ExtensionHostMsg_EventAck( | 
|  1647           background_view->GetRoutingID())); |  1648           background_view->GetRoutingID())); | 
|  1648     } |  1649     } | 
|  1649   } |  1650   } | 
|  1650 } |  1651 } | 
|  1651  |  1652  | 
|  1652 }  // namespace extensions |  1653 }  // namespace extensions | 
| OLD | NEW |