diff options
author | robertphillips@google.com <robertphillips@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-09 13:00:50 +0000 |
---|---|---|
committer | robertphillips@google.com <robertphillips@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-09 13:00:50 +0000 |
commit | 91eeff80d24dcd70ec85c04ad13867c41c51540e (patch) | |
tree | ae2d748d6397d882b38becd9f40c2956deef30b6 /chrome | |
parent | 8ea8cd2f377a2cee31f15e85432a454a27fa0af2 (diff) | |
download | chromium_src-91eeff80d24dcd70ec85c04ad13867c41c51540e.zip chromium_src-91eeff80d24dcd70ec85c04ad13867c41c51540e.tar.gz chromium_src-91eeff80d24dcd70ec85c04ad13867c41c51540e.tar.bz2 |
Revert 227722 "Introduce a new attribute to externally_connectable,"
> Introduce a new attribute to externally_connectable,
> accepts_tls_channel_id. When sites are allowed to connect to an
> extension, and specify include_tls_channel_id in their
> chrome.runtime.connect or chrome.runtime.sendMessage options,
> and the extension sets the accepts_tls_channel_id attribute,
> automatically annotate the TLS channel ID as an attribute of the
> MessageSender given to the onConnectExternal handler.
>
> BUG=259097
>
> Review URL: https://codereview.chromium.org/23002007
TBR=juanlang@google.com
Review URL: https://codereview.chromium.org/26686002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227723 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
33 files changed, 104 insertions, 1005 deletions
diff --git a/chrome/browser/extensions/api/messaging/extension_message_port.cc b/chrome/browser/extensions/api/messaging/extension_message_port.cc index 9d14a6e..e4782c7 100644 --- a/chrome/browser/extensions/api/messaging/extension_message_port.cc +++ b/chrome/browser/extensions/api/messaging/extension_message_port.cc @@ -29,15 +29,13 @@ void ExtensionMessagePort::DispatchOnConnect( const base::DictionaryValue& source_tab, const std::string& source_extension_id, const std::string& target_extension_id, - const GURL& source_url, - const std::string& tls_channel_id) { + const GURL& source_url) { ExtensionMsg_ExternalConnectionInfo info; info.target_id = target_extension_id; info.source_id = source_extension_id; info.source_url = source_url; process_->Send(new ExtensionMsg_DispatchOnConnect( - routing_id_, dest_port_id, channel_name, source_tab, info, - tls_channel_id)); + routing_id_, dest_port_id, channel_name, source_tab, info)); } void ExtensionMessagePort::DispatchOnDisconnect( diff --git a/chrome/browser/extensions/api/messaging/extension_message_port.h b/chrome/browser/extensions/api/messaging/extension_message_port.h index 1e7b788..ccf9b69 100644 --- a/chrome/browser/extensions/api/messaging/extension_message_port.h +++ b/chrome/browser/extensions/api/messaging/extension_message_port.h @@ -27,8 +27,7 @@ class ExtensionMessagePort : public MessageService::MessagePort { const base::DictionaryValue& source_tab, const std::string& source_extension_id, const std::string& target_extension_id, - const GURL& source_url, - const std::string& tls_channel_id) OVERRIDE; + const GURL& source_url) OVERRIDE; virtual void DispatchOnDisconnect(int source_port_id, const std::string& error_message) OVERRIDE; virtual void DispatchOnMessage(const std::string& message, diff --git a/chrome/browser/extensions/api/messaging/message_property_provider.cc b/chrome/browser/extensions/api/messaging/message_property_provider.cc deleted file mode 100644 index dba35c8..0000000 --- a/chrome/browser/extensions/api/messaging/message_property_provider.cc +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/extensions/api/messaging/message_property_provider.h" - -#include "base/json/json_writer.h" -#include "base/logging.h" -#include "base/message_loop/message_loop_proxy.h" -#include "base/strings/string_piece.h" -#include "base/values.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/common/extensions/api/runtime.h" -#include "content/public/browser/browser_thread.h" -#include "net/base/completion_callback.h" -#include "net/cert/asn1_util.h" -#include "net/cert/jwk_serializer.h" -#include "net/ssl/server_bound_cert_service.h" -#include "net/url_request/url_request_context.h" -#include "net/url_request/url_request_context_getter.h" -#include "url/gurl.h" - -namespace extensions { - -MessagePropertyProvider::MessagePropertyProvider() {} - -void MessagePropertyProvider::GetDomainBoundCert(Profile* profile, - const GURL& source_url, const DomainBoundCertCallback& reply) { - if (!source_url.is_valid()) { - // This isn't a real URL, so there's no sense in looking for a channel ID - // for it. Dispatch with an empty tls channel ID. - reply.Run(std::string()); - return; - } - scoped_refptr<net::URLRequestContextGetter> request_context_getter( - profile->GetRequestContext()); - content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, - base::Bind(&MessagePropertyProvider::GetDomainBoundCertOnIOThread, - base::MessageLoopProxy::current(), - request_context_getter, - source_url.host(), - reply)); -} - -// Helper struct to bind the memory addresses that will be written to by -// ServerBoundCertService::GetDomainBoundCert to the callback provided to -// MessagePropertyProvider::GetDomainBoundCert. -struct MessagePropertyProvider::GetDomainBoundCertOutput { - std::string domain_bound_private_key; - std::string domain_bound_cert; - net::ServerBoundCertService::RequestHandle request_handle; -}; - -// static -void MessagePropertyProvider::GetDomainBoundCertOnIOThread( - scoped_refptr<base::TaskRunner> original_task_runner, - scoped_refptr<net::URLRequestContextGetter> request_context_getter, - const std::string& host, - const DomainBoundCertCallback& reply) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); - net::ServerBoundCertService* server_bound_cert_service = - request_context_getter->GetURLRequestContext()-> - server_bound_cert_service(); - GetDomainBoundCertOutput* output = new GetDomainBoundCertOutput(); - net::CompletionCallback net_completion_callback = - base::Bind(&MessagePropertyProvider::GotDomainBoundCert, - original_task_runner, - base::Owned(output), - reply); - int status = server_bound_cert_service->GetDomainBoundCert( - host, - &output->domain_bound_private_key, - &output->domain_bound_cert, - net_completion_callback, - &output->request_handle); - if (status == net::ERR_IO_PENDING) - return; - GotDomainBoundCert(original_task_runner, output, reply, status); -} - -// static -void MessagePropertyProvider::GotDomainBoundCert( - scoped_refptr<base::TaskRunner> original_task_runner, - struct GetDomainBoundCertOutput* output, - const DomainBoundCertCallback& reply, - int status) { - base::Closure no_tls_channel_id_closure = - base::Bind(reply, api::runtime::NO_TLS_CHANNEL_ID); - if (status != net::OK) { - original_task_runner->PostTask(FROM_HERE, no_tls_channel_id_closure); - return; - } - base::StringPiece spki; - if (!net::asn1::ExtractSPKIFromDERCert(output->domain_bound_cert, &spki)) { - original_task_runner->PostTask(FROM_HERE, no_tls_channel_id_closure); - return; - } - base::DictionaryValue jwk_value; - if (!net::JwkSerializer::ConvertSpkiFromDerToJwk(spki, &jwk_value)) { - original_task_runner->PostTask(FROM_HERE, no_tls_channel_id_closure); - return; - } - std::string jwk_str; - base::JSONWriter::Write(&jwk_value, &jwk_str); - original_task_runner->PostTask(FROM_HERE, base::Bind(reply, jwk_str)); -} - -} // namespace extensions diff --git a/chrome/browser/extensions/api/messaging/message_property_provider.h b/chrome/browser/extensions/api/messaging/message_property_provider.h deleted file mode 100644 index 849aaae..0000000 --- a/chrome/browser/extensions/api/messaging/message_property_provider.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_PROPERTY_PROVIDER_H_ -#define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_PROPERTY_PROVIDER_H_ - -#include <string> - -#include "base/callback.h" - -class GURL; -class Profile; - -namespace base { -class TaskRunner; -} - -namespace net { -class URLRequestContextGetter; -} - -namespace extensions { - -// This class provides properties of messages asynchronously. -class MessagePropertyProvider { - public: - MessagePropertyProvider(); - - typedef base::Callback<void(const std::string&)> DomainBoundCertCallback; - - // Gets the DER-encoded public key of the domain-bound cert, - // aka TLS channel ID, for the given URL. - // Runs |reply| on the current message loop. - void GetDomainBoundCert(Profile* profile, - const GURL& source_url, - const DomainBoundCertCallback& reply); - - private: - struct GetDomainBoundCertOutput; - - static void GetDomainBoundCertOnIOThread( - scoped_refptr<base::TaskRunner> original_task_runner, - scoped_refptr<net::URLRequestContextGetter> request_context_getter, - const std::string& host, - const DomainBoundCertCallback& reply); - - static void GotDomainBoundCert( - scoped_refptr<base::TaskRunner> original_task_runner, - struct GetDomainBoundCertOutput* output, - const DomainBoundCertCallback& reply, - int status); - - DISALLOW_COPY_AND_ASSIGN(MessagePropertyProvider); -}; - -} // namespace extensions - -#endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_PROPERTY_PROVIDER_H_ diff --git a/chrome/browser/extensions/api/messaging/message_service.cc b/chrome/browser/extensions/api/messaging/message_service.cc index db57a4e..cd29d98 100644 --- a/chrome/browser/extensions/api/messaging/message_service.cc +++ b/chrome/browser/extensions/api/messaging/message_service.cc @@ -30,6 +30,7 @@ #include "chrome/common/extensions/features/simple_feature.h" #include "chrome/common/extensions/incognito_handler.h" #include "chrome/common/extensions/manifest_handlers/externally_connectable.h" +#include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" @@ -38,7 +39,6 @@ #include "content/public/browser/site_instance.h" #include "content/public/browser/web_contents.h" #include "extensions/common/manifest_constants.h" -#include "net/base/completion_callback.h" #include "url/gurl.h" using content::SiteInstance; @@ -77,8 +77,6 @@ struct MessageService::OpenChannelParams { std::string target_extension_id; GURL source_url; std::string channel_name; - bool include_tls_channel_id; - std::string tls_channel_id; // Takes ownership of receiver. OpenChannelParams(content::RenderProcessHost* source, @@ -88,16 +86,14 @@ struct MessageService::OpenChannelParams { const std::string& source_extension_id, const std::string& target_extension_id, const GURL& source_url, - const std::string& channel_name, - bool include_tls_channel_id) + const std::string& channel_name) : source(source), receiver(receiver), receiver_port_id(receiver_port_id), source_extension_id(source_extension_id), target_extension_id(target_extension_id), source_url(source_url), - channel_name(channel_name), - include_tls_channel_id(include_tls_channel_id) { + channel_name(channel_name) { if (source_tab) this->source_tab.Swap(source_tab.get()); } @@ -191,8 +187,7 @@ void MessageService::OpenChannelToExtension( const std::string& source_extension_id, const std::string& target_extension_id, const GURL& source_url, - const std::string& channel_name, - bool include_tls_channel_id) { + const std::string& channel_name) { content::RenderProcessHost* source = content::RenderProcessHost::FromID(source_process_id); if (!source) @@ -241,10 +236,6 @@ void MessageService::OpenChannelToExtension( // URL matches. is_externally_connectable = externally_connectable->matches.MatchesURL(source_url); - // Only include the TLS channel ID for externally connected web pages. - include_tls_channel_id &= - is_externally_connectable && - externally_connectable->accepts_tls_channel_id; } else { // Source extension ID so the source was an extension. Check that the // extension matches. @@ -293,29 +284,12 @@ void MessageService::OpenChannelToExtension( source_extension_id, target_extension_id, source_url_for_tab, - channel_name, - include_tls_channel_id); - - // If the target requests the TLS channel id, begin the lookup for it. - // The target might also be a lazy background page, checked next, but the - // loading of lazy background pages continues asynchronously, so enqueue - // messages awaiting TLS channel ID first. - if (include_tls_channel_id) { - pending_tls_channel_id_channels_[GET_CHANNEL_ID(params->receiver_port_id)] - = PendingMessagesQueue(); - property_provider_.GetDomainBoundCert(profile, params->source_url, - base::Bind(&MessageService::GotDomainBoundCert, - weak_factory_.GetWeakPtr(), - base::Passed(make_scoped_ptr(params)))); - return; - } + channel_name); // The target might be a lazy background page. In that case, we have to check // if it is loaded and ready, and if not, queue up the task and load the // page. - if (MaybeAddPendingLazyBackgroundPageOpenChannelTask(profile, - target_extension, - params)) { + if (MaybeAddPendingOpenChannelTask(profile, target_extension, params)) { return; } @@ -423,8 +397,7 @@ void MessageService::OpenChannelToTab( extension_id, extension_id, GURL(), // Source URL doesn't make sense for opening to tabs. - channel_name, - false)); // Connections to tabs don't get TLS channel IDs. + channel_name)); OpenChannelImpl(params.Pass()); } @@ -462,8 +435,7 @@ bool MessageService::OpenChannelImpl(scoped_ptr<OpenChannelParams> params) { params->source_tab, params->source_extension_id, params->target_extension_id, - params->source_url, - params->tls_channel_id); + params->source_url); // Keep both ends of the channel alive until the channel is closed. channel->opener->IncrementLazyKeepaliveCount(); @@ -475,7 +447,7 @@ void MessageService::AddChannel(MessageChannel* channel, int receiver_port_id) { int channel_id = GET_CHANNEL_ID(receiver_port_id); CHECK(channels_.find(channel_id) == channels_.end()); channels_[channel_id] = channel; - pending_lazy_background_page_channels_.erase(channel_id); + pending_channels_.erase(channel_id); } void MessageService::CloseChannel(int port_id, @@ -484,12 +456,11 @@ void MessageService::CloseChannel(int port_id, int channel_id = GET_CHANNEL_ID(port_id); MessageChannelMap::iterator it = channels_.find(channel_id); if (it == channels_.end()) { - PendingLazyBackgroundPageChannelMap::iterator pending = - pending_lazy_background_page_channels_.find(channel_id); - if (pending != pending_lazy_background_page_channels_.end()) { + PendingChannelMap::iterator pending = pending_channels_.find(channel_id); + if (pending != pending_channels_.end()) { lazy_background_task_queue_->AddPendingTask( pending->second.first, pending->second.second, - base::Bind(&MessageService::PendingLazyBackgroundPageCloseChannel, + base::Bind(&MessageService::PendingCloseChannel, weak_factory_.GetWeakPtr(), port_id, error_message)); } return; @@ -527,11 +498,22 @@ void MessageService::PostMessage( if (iter == channels_.end()) { // If this channel is pending, queue up the PostMessage to run once // the channel opens. - EnqueuePendingMessage(source_port_id, channel_id, message); + PendingChannelMap::iterator pending = pending_channels_.find(channel_id); + if (pending != pending_channels_.end()) { + lazy_background_task_queue_->AddPendingTask( + pending->second.first, pending->second.second, + base::Bind(&MessageService::PendingPostMessage, + weak_factory_.GetWeakPtr(), source_port_id, message)); + } return; } - DispatchMessage(source_port_id, iter->second, message); + // Figure out which port the ID corresponds to. + int dest_port_id = GET_OPPOSITE_PORT_ID(source_port_id); + MessagePort* port = IS_OPENER_PORT_ID(dest_port_id) ? + iter->second->opener.get() : iter->second->receiver.get(); + + port->DispatchOnMessage(message, dest_port_id); } void MessageService::PostMessageFromNativeProcess(int port_id, @@ -582,49 +564,7 @@ void MessageService::OnProcessClosed(content::RenderProcessHost* process) { } } -void MessageService::EnqueuePendingMessage(int source_port_id, - int channel_id, - const std::string& message) { - PendingTlsChannelIdMap::iterator pending_for_tls_channel_id = - pending_tls_channel_id_channels_.find(channel_id); - if (pending_for_tls_channel_id != pending_tls_channel_id_channels_.end()) { - pending_for_tls_channel_id->second.push_back( - PendingMessage(source_port_id, message)); - // Pending messages must only be pending the TLS channel ID or lazy - // background page loading, never both. - return; - } - EnqueuePendingMessageForLazyBackgroundLoad(source_port_id, - channel_id, - message); -} - -void MessageService::EnqueuePendingMessageForLazyBackgroundLoad( - int source_port_id, - int channel_id, - const std::string& message) { - PendingLazyBackgroundPageChannelMap::iterator pending = - pending_lazy_background_page_channels_.find(channel_id); - if (pending != pending_lazy_background_page_channels_.end()) { - lazy_background_task_queue_->AddPendingTask( - pending->second.first, pending->second.second, - base::Bind(&MessageService::PendingLazyBackgroundPagePostMessage, - weak_factory_.GetWeakPtr(), source_port_id, message)); - } -} - -void MessageService::DispatchMessage(int source_port_id, - MessageChannel* channel, - const std::string& message) { - // Figure out which port the ID corresponds to. - int dest_port_id = GET_OPPOSITE_PORT_ID(source_port_id); - MessagePort* port = IS_OPENER_PORT_ID(dest_port_id) ? - channel->opener.get() : channel->receiver.get(); - - port->DispatchOnMessage(message, dest_port_id); -} - -bool MessageService::MaybeAddPendingLazyBackgroundPageOpenChannelTask( +bool MessageService::MaybeAddPendingOpenChannelTask( Profile* profile, const Extension* extension, OpenChannelParams* params) { @@ -640,74 +580,19 @@ bool MessageService::MaybeAddPendingLazyBackgroundPageOpenChannelTask( if (!lazy_background_task_queue_->ShouldEnqueueTask(profile, extension)) return false; - pending_lazy_background_page_channels_[ - GET_CHANNEL_ID(params->receiver_port_id)] = - PendingLazyBackgroundPageChannel(profile, extension->id()); + pending_channels_[GET_CHANNEL_ID(params->receiver_port_id)] = + PendingChannel(profile, extension->id()); scoped_ptr<OpenChannelParams> scoped_params(params); lazy_background_task_queue_->AddPendingTask(profile, extension->id(), - base::Bind(&MessageService::PendingLazyBackgroundPageOpenChannel, + base::Bind(&MessageService::PendingOpenChannel, weak_factory_.GetWeakPtr(), base::Passed(&scoped_params), params->source->GetID())); return true; } -void MessageService::GotDomainBoundCert(scoped_ptr<OpenChannelParams> params, - const std::string& tls_channel_id) { - params->tls_channel_id.assign(tls_channel_id); - int channel_id = GET_CHANNEL_ID(params->receiver_port_id); - - PendingTlsChannelIdMap::iterator pending_for_tls_channel_id = - pending_tls_channel_id_channels_.find(channel_id); - if (pending_for_tls_channel_id == pending_tls_channel_id_channels_.end()) { - NOTREACHED(); - return; - } - - Profile* profile = Profile::FromBrowserContext( - params->source->GetBrowserContext()); - - const Extension* target_extension = ExtensionSystem::Get(profile)-> - extension_service()->extensions()->GetByID(params->target_extension_id); - if (!target_extension) { - pending_tls_channel_id_channels_.erase(channel_id); - DispatchOnDisconnect( - params->source, params->receiver_port_id, - kReceivingEndDoesntExistError); - return; - } - PendingMessagesQueue& pending_messages = pending_for_tls_channel_id->second; - if (MaybeAddPendingLazyBackgroundPageOpenChannelTask(profile, - target_extension, - params.get())) { - // Lazy background queue took ownership. Release ours. - ignore_result(params.release()); - // Messages queued up waiting for the TLS channel ID now need to be queued - // up for the lazy background page to load. - for (PendingMessagesQueue::iterator it = pending_messages.begin(); - it != pending_messages.end(); - it++) { - EnqueuePendingMessageForLazyBackgroundLoad(it->first, channel_id, - it->second); - } - } else { - OpenChannelImpl(params.Pass()); - // Messages queued up waiting for the TLS channel ID can be posted now. - MessageChannelMap::iterator channel_iter = channels_.find(channel_id); - if (channel_iter != channels_.end()) { - for (PendingMessagesQueue::iterator it = pending_messages.begin(); - it != pending_messages.end(); - it++) { - DispatchMessage(it->first, channel_iter->second, it->second); - } - } - } - pending_tls_channel_id_channels_.erase(channel_id); -} - -void MessageService::PendingLazyBackgroundPageOpenChannel( - scoped_ptr<OpenChannelParams> params, - int source_process_id, - ExtensionHost* host) { +void MessageService::PendingOpenChannel(scoped_ptr<OpenChannelParams> params, + int source_process_id, + ExtensionHost* host) { if (!host) return; // TODO(mpcomplete): notify source of disconnect? diff --git a/chrome/browser/extensions/api/messaging/message_service.h b/chrome/browser/extensions/api/messaging/message_service.h index 168da41..6de5a74 100644 --- a/chrome/browser/extensions/api/messaging/message_service.h +++ b/chrome/browser/extensions/api/messaging/message_service.h @@ -8,12 +8,10 @@ #include <map> #include <set> #include <string> -#include <vector> #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "chrome/browser/extensions/api/messaging/message_property_provider.h" #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" #include "content/public/browser/notification_observer.h" @@ -76,8 +74,7 @@ class MessageService : public ProfileKeyedAPI, const base::DictionaryValue& source_tab, const std::string& source_extension_id, const std::string& target_extension_id, - const GURL& source_url, - const std::string& tls_channel_id) {} + const GURL& source_url) {} // Notify the port that the channel has been closed. If |error_message| is // non-empty, it indicates an error occurred while opening the connection. @@ -124,8 +121,7 @@ class MessageService : public ProfileKeyedAPI, const std::string& source_extension_id, const std::string& target_extension_id, const GURL& source_url, - const std::string& channel_name, - bool include_tls_channel_id); + const std::string& channel_name); // Same as above, but opens a channel to the tab with the given ID. Messages // are restricted to that tab, so if there are multiple tabs in that process, @@ -147,8 +143,7 @@ class MessageService : public ProfileKeyedAPI, virtual void CloseChannel(int port_id, const std::string& error_message) OVERRIDE; - // Enqueues a message on a pending channel, or sends a message to the given - // port if the channel isn't pending. + // Sends a message to the given port. void PostMessage(int port_id, const std::string& message); // NativeMessageProcessHost::Client @@ -164,18 +159,11 @@ class MessageService : public ProfileKeyedAPI, // A map of channel ID to its channel object. typedef std::map<int, MessageChannel*> MessageChannelMap; - typedef std::pair<int, std::string> PendingMessage; - typedef std::vector<PendingMessage> PendingMessagesQueue; - // A set of channel IDs waiting for TLS channel IDs to complete opening, - // and any pending messages queued to be sent on those channels. - typedef std::map<int, PendingMessagesQueue> PendingTlsChannelIdMap; - // A map of channel ID to information about the extension that is waiting // for that channel to open. Used for lazy background pages. typedef std::string ExtensionID; - typedef std::pair<Profile*, ExtensionID> PendingLazyBackgroundPageChannel; - typedef std::map<int, PendingLazyBackgroundPageChannel> - PendingLazyBackgroundPageChannelMap; + typedef std::pair<Profile*, ExtensionID> PendingChannel; + typedef std::map<int, PendingChannel> PendingChannelMap; // Common among OpenChannel* variants. bool OpenChannelImpl(scoped_ptr<OpenChannelParams> params); @@ -197,46 +185,28 @@ class MessageService : public ProfileKeyedAPI, // A process that might be in our list of channels has closed. void OnProcessClosed(content::RenderProcessHost* process); - void GotDomainBoundCert(scoped_ptr<OpenChannelParams> params, - const std::string& tls_channel_id); - - // Enqueues a message on a pending channel. - void EnqueuePendingMessage(int port_id, int channel_id, - const std::string& message); - - // Enqueues a message on a channel pending on a lazy background page load. - void EnqueuePendingMessageForLazyBackgroundLoad(int port_id, - int channel_id, - const std::string& message); - - // Immediately sends a message to the given port. - void DispatchMessage(int port_id, MessageChannel* channel, - const std::string& message); - // Potentially registers a pending task with the LazyBackgroundTaskQueue // to open a channel. Returns true if a task was queued. // Takes ownership of |params| if true is returned. - bool MaybeAddPendingLazyBackgroundPageOpenChannelTask( - Profile* profile, - const Extension* extension, - OpenChannelParams* params); + bool MaybeAddPendingOpenChannelTask(Profile* profile, + const Extension* extension, + OpenChannelParams* params); // Callbacks for LazyBackgroundTaskQueue tasks. The queue passes in an // ExtensionHost to its task callbacks, though some of our callbacks don't // use that argument. - void PendingLazyBackgroundPageOpenChannel( - scoped_ptr<OpenChannelParams> params, - int source_process_id, - extensions::ExtensionHost* host); - void PendingLazyBackgroundPageCloseChannel(int port_id, - const std::string& error_message, - extensions::ExtensionHost* host) { + void PendingOpenChannel(scoped_ptr<OpenChannelParams> params, + int source_process_id, + extensions::ExtensionHost* host); + void PendingCloseChannel(int port_id, + const std::string& error_message, + extensions::ExtensionHost* host) { if (host) CloseChannel(port_id, error_message); } - void PendingLazyBackgroundPagePostMessage(int port_id, - const std::string& message, - extensions::ExtensionHost* host) { + void PendingPostMessage(int port_id, + const std::string& message, + extensions::ExtensionHost* host) { if (host) PostMessage(port_id, message); } @@ -257,9 +227,7 @@ class MessageService : public ProfileKeyedAPI, content::NotificationRegistrar registrar_; MessageChannelMap channels_; - PendingTlsChannelIdMap pending_tls_channel_id_channels_; - PendingLazyBackgroundPageChannelMap pending_lazy_background_page_channels_; - MessagePropertyProvider property_provider_; + PendingChannelMap pending_channels_; // Weak pointer. Guaranteed to outlive this class. LazyBackgroundTaskQueue* lazy_background_task_queue_; diff --git a/chrome/browser/extensions/extension_messages_apitest.cc b/chrome/browser/extensions/extension_messages_apitest.cc index 753d38a..e6557df 100644 --- a/chrome/browser/extensions/extension_messages_apitest.cc +++ b/chrome/browser/extensions/extension_messages_apitest.cc @@ -2,15 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/base64.h" #include "base/files/file_path.h" -#include "base/json/json_reader.h" -#include "base/json/json_writer.h" #include "base/path_service.h" #include "base/strings/string_number_conversions.h" -#include "base/strings/string_piece.h" #include "base/strings/stringprintf.h" -#include "base/synchronization/waitable_event.h" #include "base/values.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/event_router.h" @@ -23,18 +18,12 @@ #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/extensions/api/runtime.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_service.h" #include "content/public/test/browser_test_utils.h" -#include "net/cert/asn1_util.h" -#include "net/cert/jwk_serializer.h" #include "net/dns/mock_host_resolver.h" -#include "net/ssl/server_bound_cert_service.h" #include "net/test/embedded_test_server/embedded_test_server.h" -#include "net/url_request/url_request_context.h" -#include "net/url_request/url_request_context_getter.h" #include "url/gurl.h" namespace extensions { @@ -151,7 +140,6 @@ class ExternallyConnectableMessagingTest : public ExtensionApiTest { OTHER_ERROR = 4, INCORRECT_RESPONSE_SENDER = 5, INCORRECT_RESPONSE_MESSAGE = 6, - NO_TLS_CHANNEL_ID = 7, }; bool AppendIframe(const GURL& src) { @@ -195,7 +183,7 @@ class ExternallyConnectableMessagingTest : public ExtensionApiTest { browser->tab_strip_model()->GetActiveWebContents(), frame_xpath, base::StringPrintf("assertions.canConnectAndSendMessages(%s)", - args.c_str()), + args.c_str()).c_str(), &result)); return static_cast<Result>(result); } @@ -247,24 +235,6 @@ class ExternallyConnectableMessagingTest : public ExtensionApiTest { testing::AssertionSuccess() : testing::AssertionFailure(); } - std::string GetTlsChannelIdFromPortConnect(const std::string& extension_id, - bool include_tls_channel_id, - const char* message = NULL) { - return GetTlsChannelIdFromAssertion("getTlsChannelIdFromPortConnect", - extension_id, - include_tls_channel_id, - message); - } - - std::string GetTlsChannelIdFromSendMessage(const std::string& extension_id, - bool include_tls_channel_id, - const char* message = NULL) { - return GetTlsChannelIdFromAssertion("getTlsChannelIdFromSendMessage", - extension_id, - include_tls_channel_id, - message); - } - GURL GetURLForPath(const std::string& host, const std::string& path) { std::string port = base::IntToString(embedded_test_server()->port()); GURL::Replacements replacements; @@ -308,11 +278,6 @@ class ExternallyConnectableMessagingTest : public ExtensionApiTest { return extension; } - const Extension* LoadChromiumConnectableExtensionWithTlsChannelId() { - return LoadExtensionIntoDir(&tls_channel_id_connectable_dir_, - connectable_with_tls_channel_id_manifest()); - } - void InitializeTestServer() { base::FilePath test_data; EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data)); @@ -360,38 +325,8 @@ class ExternallyConnectableMessagingTest : public ExtensionApiTest { "\"manifest_version\": 2"; } - std::string connectable_with_tls_channel_id_manifest() { - return base::StringPrintf( - "{" - " \"name\": \"chromium_connectable_with_tls_channel_id\"," - " %s," - " \"externally_connectable\": {" - " \"matches\": [\"*://*.chromium.org:*/*\"]," - " \"accepts_tls_channel_id\": true" - " }" - "}", - common_manifest()); - } - - std::string GetTlsChannelIdFromAssertion(const char* method, - const std::string& extension_id, - bool include_tls_channel_id, - const char* message) { - std::string result; - std::string args = "'" + extension_id + "', "; - args += include_tls_channel_id ? "true" : "false"; - if (message) - args += std::string(", '") + message + "'"; - CHECK(content::ExecuteScriptAndExtractString( - browser()->tab_strip_model()->GetActiveWebContents(), - base::StringPrintf("assertions.%s(%s)", method, args.c_str()), - &result)); - return result; - } - TestExtensionDir web_connectable_dir_; TestExtensionDir not_connectable_dir_; - TestExtensionDir tls_channel_id_connectable_dir_; }; IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, NotInstalled) { @@ -460,106 +395,6 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, EXPECT_EQ(OK, CanConnectAndSendMessages(chromium_connectable->id())); } -// Tests a web connectable extension that doesn't receive TLS channel id. -IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, - WebConnectableWithoutTlsChannelId) { - InitializeTestServer(); - - // Install the web connectable extension. chromium.org can connect to it, - // google.com can't. - const Extension* chromium_connectable = LoadChromiumConnectableExtension(); - ASSERT_TRUE(chromium_connectable); - - ui_test_utils::NavigateToURL(browser(), chromium_org_url()); - // The web connectable extension doesn't request the TLS channel ID, so it - // doesn't get it, whether or not the page asks for it. - EXPECT_EQ(base::StringPrintf("%d", NO_TLS_CHANNEL_ID), - GetTlsChannelIdFromPortConnect(chromium_connectable->id(), false)); - EXPECT_EQ(base::StringPrintf("%d", NO_TLS_CHANNEL_ID), - GetTlsChannelIdFromSendMessage(chromium_connectable->id(), true)); - EXPECT_EQ(base::StringPrintf("%d", NO_TLS_CHANNEL_ID), - GetTlsChannelIdFromPortConnect(chromium_connectable->id(), false)); - EXPECT_EQ(base::StringPrintf("%d", NO_TLS_CHANNEL_ID), - GetTlsChannelIdFromSendMessage(chromium_connectable->id(), true)); -} - -// Tests a web connectable extension that receives TLS channel id with a site -// that can't connect to it. -IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, - WebConnectableWithTlsChannelIdWithNonMatchingSite) { - InitializeTestServer(); - - const Extension* chromium_connectable = - LoadChromiumConnectableExtensionWithTlsChannelId(); - ASSERT_TRUE(chromium_connectable); - - ui_test_utils::NavigateToURL(browser(), google_com_url()); - // The extension requests the TLS channel ID, but it doesn't get it for a - // site that can't connect to it, regardless of whether the page asks for it. - EXPECT_EQ(base::StringPrintf("%d", NAMESPACE_NOT_DEFINED), - GetTlsChannelIdFromPortConnect(chromium_connectable->id(), false)); - EXPECT_EQ(base::StringPrintf("%d", NAMESPACE_NOT_DEFINED), - GetTlsChannelIdFromSendMessage(chromium_connectable->id(), true)); - EXPECT_EQ(base::StringPrintf("%d", NAMESPACE_NOT_DEFINED), - GetTlsChannelIdFromPortConnect(chromium_connectable->id(), false)); - EXPECT_EQ(base::StringPrintf("%d", NAMESPACE_NOT_DEFINED), - GetTlsChannelIdFromSendMessage(chromium_connectable->id(), true)); -} - -// Tests a web connectable extension that receives TLS channel id on a site -// that can connect to it, but with no TLS channel ID having been generated. -IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, - WebConnectableWithTlsChannelIdWithEmptyTlsChannelId) { - InitializeTestServer(); - - const Extension* chromium_connectable = - LoadChromiumConnectableExtensionWithTlsChannelId(); - ASSERT_TRUE(chromium_connectable); - - ui_test_utils::NavigateToURL(browser(), chromium_org_url()); - - // Since the extension requests the TLS channel ID, it gets it for a site that - // can connect to it, but only if the page also asks to include it. - EXPECT_EQ(base::StringPrintf("%d", NO_TLS_CHANNEL_ID), - GetTlsChannelIdFromPortConnect(chromium_connectable->id(), false)); - EXPECT_EQ(base::StringPrintf("%d", NO_TLS_CHANNEL_ID), - GetTlsChannelIdFromSendMessage(chromium_connectable->id(), false)); - // If the page does ask for it, it isn't empty. - std::string tls_channel_id = - GetTlsChannelIdFromPortConnect(chromium_connectable->id(), true); - // Because the TLS channel ID has never been generated for this domain, - // the sentinel value for no TLS channel ID is reported. - EXPECT_EQ(api::runtime::NO_TLS_CHANNEL_ID, tls_channel_id); -} - -// Tests a web connectable extension that receives TLS channel id, but -// immediately closes its background page upon receipt of a message. -IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, - WebConnectableWithEmptyTlsChannelIdAndClosedBackgroundPage) { - InitializeTestServer(); - - const Extension* chromium_connectable = - LoadChromiumConnectableExtensionWithTlsChannelId(); - - ui_test_utils::NavigateToURL(browser(), chromium_org_url()); - // If the page does ask for it, it isn't empty, even if the background page - // closes upon receipt of the connect. - std::string tls_channel_id = - GetTlsChannelIdFromPortConnect(chromium_connectable->id(), - true, - close_background_message()); - // Because the TLS channel ID has never been generated for this domain, - // the sentinel value for no TLS channel ID is reported. - EXPECT_EQ(api::runtime::NO_TLS_CHANNEL_ID, tls_channel_id); - // A subsequent connect will still succeed, even if the background page was - // previously closed. - tls_channel_id = - GetTlsChannelIdFromPortConnect(chromium_connectable->id(), - true); - // And the empty value is still retrieved. - EXPECT_EQ(api::runtime::NO_TLS_CHANNEL_ID, tls_channel_id); -} - // Tests that enabling and disabling an extension makes the runtime bindings // appear and disappear. // @@ -650,157 +485,5 @@ IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, EXPECT_FALSE(AreAnyNonWebApisDefined(frame_xpath)); } -// Tests externally_connectable between a web page and an extension with a -// TLS channel ID created for the origin. -class ExternallyConnectableMessagingWithTlsChannelIdTest : - public ExternallyConnectableMessagingTest { - public: - ExternallyConnectableMessagingWithTlsChannelIdTest() - : tls_channel_id_created_(false, false) { - } - - std::string CreateTlsChannelId() { - scoped_refptr<net::URLRequestContextGetter> request_context_getter( - profile()->GetRequestContext()); - std::string domain_bound_private_key; - std::string domain_bound_cert; - net::ServerBoundCertService::RequestHandle request_handle; - content::BrowserThread::PostTask( - content::BrowserThread::IO, - FROM_HERE, - base::Bind( - &ExternallyConnectableMessagingWithTlsChannelIdTest:: - CreateDomainBoundCertOnIOThread, - base::Unretained(this), - base::Unretained(&domain_bound_private_key), - base::Unretained(&domain_bound_cert), - base::Unretained(&request_handle), - request_context_getter)); - tls_channel_id_created_.Wait(); - // Create the expected value. - base::StringPiece spki; - net::asn1::ExtractSPKIFromDERCert(domain_bound_cert, &spki); - base::DictionaryValue jwk_value; - net::JwkSerializer::ConvertSpkiFromDerToJwk(spki, &jwk_value); - std::string tls_channel_id_value; - base::JSONWriter::Write(&jwk_value, &tls_channel_id_value); - return tls_channel_id_value; - } - - private: - void CreateDomainBoundCertOnIOThread( - std::string* domain_bound_private_key, - std::string* domain_bound_cert, - net::ServerBoundCertService::RequestHandle* request_handle, - scoped_refptr<net::URLRequestContextGetter> request_context_getter) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); - net::ServerBoundCertService* server_bound_cert_service = - request_context_getter->GetURLRequestContext()-> - server_bound_cert_service(); - int status = server_bound_cert_service->GetOrCreateDomainBoundCert( - chromium_org_url().host(), - domain_bound_private_key, - domain_bound_cert, - base::Bind(&ExternallyConnectableMessagingWithTlsChannelIdTest:: - GotDomainBoundCert, - base::Unretained(this)), - request_handle); - if (status == net::ERR_IO_PENDING) - return; - GotDomainBoundCert(status); - } - - void GotDomainBoundCert(int status) { - ASSERT_TRUE(status == net::OK); - tls_channel_id_created_.Signal(); - } - - base::WaitableEvent tls_channel_id_created_; -}; - -// Tests a web connectable extension that receives TLS channel id on a site -// that can connect to it, with a TLS channel ID having been generated. -IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingWithTlsChannelIdTest, - WebConnectableWithNonEmptyTlsChannelId) { - InitializeTestServer(); - std::string expected_tls_channel_id_value = CreateTlsChannelId(); - - const Extension* chromium_connectable = - LoadChromiumConnectableExtensionWithTlsChannelId(); - ASSERT_TRUE(chromium_connectable); - - ui_test_utils::NavigateToURL(browser(), chromium_org_url()); - - // Since the extension requests the TLS channel ID, it gets it for a site that - // can connect to it, but only if the page also asks to send it. - EXPECT_EQ(base::StringPrintf("%d", NO_TLS_CHANNEL_ID), - GetTlsChannelIdFromPortConnect(chromium_connectable->id(), false)); - EXPECT_EQ(base::StringPrintf("%d", NO_TLS_CHANNEL_ID), - GetTlsChannelIdFromSendMessage(chromium_connectable->id(), false)); - - // If the page does ask to send the TLS channel ID, it's sent and non-empty. - std::string tls_channel_id_from_port_connect = - GetTlsChannelIdFromPortConnect(chromium_connectable->id(), true); - EXPECT_NE(0u, tls_channel_id_from_port_connect.size()); - - // The same value is received by both connect and sendMessage. - std::string tls_channel_id_from_send_message = - GetTlsChannelIdFromSendMessage(chromium_connectable->id(), true); - EXPECT_EQ(tls_channel_id_from_port_connect, tls_channel_id_from_send_message); - - // And since a TLS channel ID exists for the domain, the value received is - // parseable as a JWK. (In particular, it has the same value we created by - // converting the public key to JWK with net::ConvertSpkiFromDerToJwk.) - std::string tls_channel_id(tls_channel_id_from_port_connect); - EXPECT_EQ(expected_tls_channel_id_value, tls_channel_id); - - // The TLS channel ID shouldn't change from one connection to the next... - std::string tls_channel_id2 = - GetTlsChannelIdFromPortConnect(chromium_connectable->id(), true); - EXPECT_EQ(tls_channel_id, tls_channel_id2); - tls_channel_id2 = - GetTlsChannelIdFromSendMessage(chromium_connectable->id(), true); - EXPECT_EQ(tls_channel_id, tls_channel_id2); - - // nor should it change when navigating away, revisiting the page and - // requesting it again. - ui_test_utils::NavigateToURL(browser(), google_com_url()); - ui_test_utils::NavigateToURL(browser(), chromium_org_url()); - tls_channel_id2 = - GetTlsChannelIdFromPortConnect(chromium_connectable->id(), true); - EXPECT_EQ(tls_channel_id, tls_channel_id2); - tls_channel_id2 = - GetTlsChannelIdFromSendMessage(chromium_connectable->id(), true); - EXPECT_EQ(tls_channel_id, tls_channel_id2); -} - -// Tests a web connectable extension that receives TLS channel id, but -// immediately closes its background page upon receipt of a message. -// Same flakiness seen in http://crbug.com/297866 -IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingWithTlsChannelIdTest, - DISABLED_WebConnectableWithNonEmptyTlsChannelIdAndClosedBackgroundPage) { - InitializeTestServer(); - std::string expected_tls_channel_id_value = CreateTlsChannelId(); - - const Extension* chromium_connectable = - LoadChromiumConnectableExtensionWithTlsChannelId(); - - ui_test_utils::NavigateToURL(browser(), chromium_org_url()); - // If the page does ask for it, it isn't empty, even if the background page - // closes upon receipt of the connect. - std::string tls_channel_id = - GetTlsChannelIdFromPortConnect(chromium_connectable->id(), - true, - close_background_message()); - EXPECT_EQ(expected_tls_channel_id_value, tls_channel_id); - // A subsequent connect will still succeed, even if the background page was - // previously closed. - tls_channel_id = - GetTlsChannelIdFromPortConnect(chromium_connectable->id(), - true); - // And the expected value is still retrieved. - EXPECT_EQ(expected_tls_channel_id_value, tls_channel_id); -} - } // namespace }; // namespace extensions diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.cc b/chrome/browser/renderer_host/chrome_render_message_filter.cc index 2d69147..b7cb9c5 100644 --- a/chrome/browser/renderer_host/chrome_render_message_filter.cc +++ b/chrome/browser/renderer_host/chrome_render_message_filter.cc @@ -284,9 +284,7 @@ void ChromeRenderMessageFilter::OnV8HeapStats(int v8_memory_allocated, void ChromeRenderMessageFilter::OnOpenChannelToExtension( int routing_id, const ExtensionMsg_ExternalConnectionInfo& info, - const std::string& channel_name, - bool include_tls_channel_id, - int* port_id) { + const std::string& channel_name, int* port_id) { int port2_id; extensions::MessageService::AllocatePortIdPair(port_id, &port2_id); @@ -294,20 +292,18 @@ void ChromeRenderMessageFilter::OnOpenChannelToExtension( BrowserThread::UI, FROM_HERE, base::Bind(&ChromeRenderMessageFilter::OpenChannelToExtensionOnUIThread, this, render_process_id_, routing_id, port2_id, info, - channel_name, include_tls_channel_id)); + channel_name)); } void ChromeRenderMessageFilter::OpenChannelToExtensionOnUIThread( int source_process_id, int source_routing_id, int receiver_port_id, const ExtensionMsg_ExternalConnectionInfo& info, - const std::string& channel_name, - bool include_tls_channel_id) { + const std::string& channel_name) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); extensions::MessageService::Get(profile_)->OpenChannelToExtension( source_process_id, source_routing_id, receiver_port_id, - info.source_id, info.target_id, info.source_url, channel_name, - include_tls_channel_id); + info.source_id, info.target_id, info.source_url, channel_name); } void ChromeRenderMessageFilter::OnOpenChannelToNativeApp( diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.h b/chrome/browser/renderer_host/chrome_render_message_filter.h index 76105fac..a446928 100644 --- a/chrome/browser/renderer_host/chrome_render_message_filter.h +++ b/chrome/browser/renderer_host/chrome_render_message_filter.h @@ -88,16 +88,13 @@ class ChromeRenderMessageFilter : public content::BrowserMessageFilter { void OnV8HeapStats(int v8_memory_allocated, int v8_memory_used); void OnOpenChannelToExtension(int routing_id, const ExtensionMsg_ExternalConnectionInfo& info, - const std::string& channel_name, - bool include_tls_channel_id, - int* port_id); + const std::string& channel_name, int* port_id); void OpenChannelToExtensionOnUIThread( int source_process_id, int source_routing_id, int receiver_port_id, const ExtensionMsg_ExternalConnectionInfo& info, - const std::string& channel_name, - bool include_tls_channel_id); + const std::string& channel_name); void OnOpenChannelToNativeApp(int routing_id, const std::string& source_extension_id, const std::string& native_app_name, diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi index 83d5ac1..d36fc75 100644 --- a/chrome/chrome_browser_extensions.gypi +++ b/chrome/chrome_browser_extensions.gypi @@ -351,8 +351,6 @@ 'browser/extensions/api/media_galleries_private/media_galleries_private_event_router.h', 'browser/extensions/api/messaging/extension_message_port.cc', 'browser/extensions/api/messaging/extension_message_port.h', - 'browser/extensions/api/messaging/message_property_provider.cc', - 'browser/extensions/api/messaging/message_property_provider.h', 'browser/extensions/api/messaging/message_service.cc', 'browser/extensions/api/messaging/message_service.h', 'browser/extensions/api/messaging/native_message_process_host.cc', @@ -927,7 +925,6 @@ ['include', '^browser/extensions/api/extension_action/extension_action_api.cc'], ['include', '^browser/extensions/api/extension_action/extension_page_actions_api_constants.cc'], ['include', '^browser/extensions/api/messaging/extension_message_port.cc'], - ['include', '^browser/extensions/api/messaging/message_property_provider.cc'], ['include', '^browser/extensions/api/messaging/message_service.cc'], ['include', '^browser/extensions/api/module/module.cc'], ['include', '^browser/extensions/api/omnibox/omnibox_api.cc'], diff --git a/chrome/common/extensions/api/manifest_types.json b/chrome/common/extensions/api/manifest_types.json index e765138..1658cf6 100644 --- a/chrome/common/extensions/api/manifest_types.json +++ b/chrome/common/extensions/api/manifest_types.json @@ -30,11 +30,6 @@ "optional": true, "type": "array", "items": {"type": "string"} - }, - "accepts_tls_channel_id": { - "description": "If <code>true</true>, messages sent via $ref:runtime.connect or $ref:runtime.sendMessage will set $ref:runtime.MessageSender.tlsChannelId if those methods request it to be. If <code>false</code>, $ref:runtime.MessageSender.tlsChannelId will never be set under any circumstance.", - "optional": true, - "type": "boolean" } } }, diff --git a/chrome/common/extensions/api/runtime.json b/chrome/common/extensions/api/runtime.json index 4da468a..69f53e8 100644 --- a/chrome/common/extensions/api/runtime.json +++ b/chrome/common/extensions/api/runtime.json @@ -34,8 +34,7 @@ "properties": { "tab": {"$ref": "tabs.Tab", "optional": true, "description": "The $ref:tabs.Tab which opened the connection, if any. This property will <strong>only</strong> be present when the connection was opened from a tab (including content scripts), and <strong>only</strong> if the receiver is an extension, not an app."}, "id": {"type": "string", "optional": true, "description": "The ID of the extension or app that opened the connection, if any."}, - "url": {"type": "string", "optional": true, "description": "The URL of the page or frame that opened the connection, if any. This property will <strong>only</strong> be present when the connection was opened from a tab or content script."}, - "tlsChannelId": {"type": "string", "optional": true, "description": "The TLS channel ID of the web page that opened the connection, if requested by the extension or app, and if available."} + "url": {"type": "string", "optional": true, "description": "The URL of the page or frame that opened the connection, if any. This property will <strong>only</strong> be present when the connection was opened from a tab or content script."} } } ], @@ -55,11 +54,6 @@ "id": { "type": "string", "description": "The ID of the extension/app." - }, - "NO_TLS_CHANNEL_ID": { - "type": "string", - "value": "\"<No TLS channel ID>\"", - "description": "The value $ref:runtime.MessageSender.tlsChannelId will have if a TLS channel ID was requested, but none has yet been set for the domain of the web page that requested it." } }, "functions": [ @@ -185,8 +179,7 @@ "type": "object", "name": "connectInfo", "properties": { - "name": { "type": "string", "optional": true, "description": "Will be passed into onConnect for processes that are listening for the connection event." }, - "includeTlsChannelId": { "type": "boolean", "optional": true, "description": "Whether the TLS channel ID will be passed into onConnectExternal for processes that are listening for the connection event." } + "name": { "type": "string", "optional": true, "description": "Will be passed into onConnect for processes that are listening for the connection event." } }, "optional": true } @@ -223,14 +216,6 @@ {"type": "string", "name": "extensionId", "optional": true, "description": "The extension ID of the extension you want to connect to. If omitted, default is your own extension."}, { "type": "any", "name": "message" }, { - "type": "object", - "name": "options", - "properties": { - "includeTlsChannelId": { "type": "boolean", "optional": true, "description": "Whether the TLS channel ID will be passed into onMessageExternal for processes that are listening for the connection event." } - }, - "optional": true - }, - { "type": "function", "name": "responseCallback", "optional": true, diff --git a/chrome/common/extensions/docs/templates/articles/manifest/externally_connectable.html b/chrome/common/extensions/docs/templates/articles/manifest/externally_connectable.html index a2015ae..647ef46 100644 --- a/chrome/common/extensions/docs/templates/articles/manifest/externally_connectable.html +++ b/chrome/common/extensions/docs/templates/articles/manifest/externally_connectable.html @@ -34,13 +34,7 @@ If <code>externally_connectable</code> is not declared in your {{platform}}'s ma "https://*.google.com", "*://*.chromium.org", ... - ], - // Indicates that the extension would like to make use of the TLS channel - // ID of the web page connecting to it. The web page must also opt to send - // the TLS channel ID to the extension via setting - // <code>includeTlsChannelId</code> to <code>true</code> in - // $ref:runtime.connect's connectInfo or $ref:runtime.sendMessage's options. - "accepts_tls_channel_id": false + ] }, ... } diff --git a/chrome/common/extensions/extension_messages.h b/chrome/common/extensions/extension_messages.h index e947497..de20726 100644 --- a/chrome/common/extensions/extension_messages.h +++ b/chrome/common/extensions/extension_messages.h @@ -426,12 +426,11 @@ IPC_MESSAGE_ROUTED2(ExtensionMsg_GetAppInstallStateResponse, int32 /* callback_id */) // Dispatch the Port.onConnect event for message channels. -IPC_MESSAGE_ROUTED5(ExtensionMsg_DispatchOnConnect, +IPC_MESSAGE_ROUTED4(ExtensionMsg_DispatchOnConnect, int /* target_port_id */, std::string /* channel_name */, base::DictionaryValue /* source_tab */, - ExtensionMsg_ExternalConnectionInfo, - std::string /* tls_channel_id */) + ExtensionMsg_ExternalConnectionInfo) // Deliver a message sent with ExtensionHostMsg_PostMessage. IPC_MESSAGE_ROUTED2(ExtensionMsg_DeliverMessage, @@ -521,11 +520,10 @@ IPC_MESSAGE_ROUTED0(ExtensionHostMsg_EventAck) // the given ID. This always returns a valid port ID which can be used for // sending messages. If an error occurred, the opener will be notified // asynchronously. -IPC_SYNC_MESSAGE_CONTROL4_1(ExtensionHostMsg_OpenChannelToExtension, +IPC_SYNC_MESSAGE_CONTROL3_1(ExtensionHostMsg_OpenChannelToExtension, int /* routing_id */, ExtensionMsg_ExternalConnectionInfo, std::string /* channel_name */, - bool /* include_tls_channel_id */, int /* port_id */) IPC_SYNC_MESSAGE_CONTROL3_1(ExtensionHostMsg_OpenChannelToNativeApp, diff --git a/chrome/common/extensions/manifest_handlers/externally_connectable.cc b/chrome/common/extensions/manifest_handlers/externally_connectable.cc index 8d06248..8104a45 100644 --- a/chrome/common/extensions/manifest_handlers/externally_connectable.cc +++ b/chrome/common/extensions/manifest_handlers/externally_connectable.cc @@ -185,12 +185,8 @@ scoped_ptr<ExternallyConnectableInfo> ExternallyConnectableInfo::FromValue( keys::kExternallyConnectable)); } - bool accepts_tls_channel_id = - externally_connectable->accepts_tls_channel_id.get() && - *externally_connectable->accepts_tls_channel_id; return make_scoped_ptr( - new ExternallyConnectableInfo(matches, ids, all_ids, - accepts_tls_channel_id)); + new ExternallyConnectableInfo(matches, ids, all_ids)); } ExternallyConnectableInfo::~ExternallyConnectableInfo() {} @@ -198,10 +194,8 @@ ExternallyConnectableInfo::~ExternallyConnectableInfo() {} ExternallyConnectableInfo::ExternallyConnectableInfo( const URLPatternSet& matches, const std::vector<std::string>& ids, - bool all_ids, - bool accepts_tls_channel_id) - : matches(matches), ids(Sorted(ids)), all_ids(all_ids), - accepts_tls_channel_id(accepts_tls_channel_id) {} + bool all_ids) + : matches(matches), ids(Sorted(ids)), all_ids(all_ids) {} bool ExternallyConnectableInfo::IdCanConnect(const std::string& id) { if (all_ids) diff --git a/chrome/common/extensions/manifest_handlers/externally_connectable.h b/chrome/common/extensions/manifest_handlers/externally_connectable.h index 328216e..97d0d02 100644 --- a/chrome/common/extensions/manifest_handlers/externally_connectable.h +++ b/chrome/common/extensions/manifest_handlers/externally_connectable.h @@ -72,10 +72,6 @@ struct ExternallyConnectableInfo : public Extension::ManifestData { // to an ID of "*" in |ids|. const bool all_ids; - // True if extension accepts the TLS channel ID, when requested by the - // connecting origin. - const bool accepts_tls_channel_id; - // Returns true if |ids| contains |id| or if |all_ids| is true. // // More convenient for callers than checking each individually, and it makes @@ -85,8 +81,7 @@ struct ExternallyConnectableInfo : public Extension::ManifestData { // Public only for testing. Use FromValue in production. ExternallyConnectableInfo(const URLPatternSet& matches, const std::vector<std::string>& ids, - bool all_ids, - bool accepts_tls_channel_id); + bool all_ids); private: DISALLOW_COPY_AND_ASSIGN(ExternallyConnectableInfo); diff --git a/chrome/common/extensions/manifest_handlers/externally_connectable_unittest.cc b/chrome/common/extensions/manifest_handlers/externally_connectable_unittest.cc index 2e5d993..c215f2b 100644 --- a/chrome/common/extensions/manifest_handlers/externally_connectable_unittest.cc +++ b/chrome/common/extensions/manifest_handlers/externally_connectable_unittest.cc @@ -127,8 +127,6 @@ TEST_F(ExternallyConnectableTest, Matches) { EXPECT_FALSE(info->all_ids); - EXPECT_FALSE(info->accepts_tls_channel_id); - EXPECT_TRUE(info->matches.MatchesURL(GURL("http://example.com"))); EXPECT_TRUE(info->matches.MatchesURL(GURL("http://example.com/"))); EXPECT_FALSE(info->matches.MatchesURL(GURL("http://example.com/index.html"))); @@ -154,31 +152,6 @@ TEST_F(ExternallyConnectableTest, Matches) { EXPECT_FALSE(info->matches.MatchesURL(GURL("http://yahoo.com/"))); } -TEST_F(ExternallyConnectableTest, MatchesWithTlsChannelId) { - scoped_refptr<Extension> extension = - LoadAndExpectSuccess( - "externally_connectable_matches_tls_channel_id.json"); - ASSERT_TRUE(extension.get()); - - EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kWebConnectable)); - - ExternallyConnectableInfo* info = - ExternallyConnectableInfo::Get(extension.get()); - ASSERT_TRUE(info); - - EXPECT_THAT(info->ids, ElementsAre()); - - EXPECT_FALSE(info->all_ids); - - EXPECT_TRUE(info->accepts_tls_channel_id); - - // The matches portion of the manifest is identical to those in - // externally_connectable_matches, so only a subset of the Matches tests is - // repeated here. - EXPECT_TRUE(info->matches.MatchesURL(GURL("http://example.com"))); - EXPECT_FALSE(info->matches.MatchesURL(GURL("http://example.com/index.html"))); -} - TEST_F(ExternallyConnectableTest, AllIDs) { scoped_refptr<Extension> extension = LoadAndExpectSuccess("externally_connectable_all_ids.json"); @@ -208,7 +181,7 @@ TEST_F(ExternallyConnectableTest, IdCanConnect) { // all_ids = false. { - ExternallyConnectableInfo info(URLPatternSet(), matches_ids, false, false); + ExternallyConnectableInfo info(URLPatternSet(), matches_ids, false); for (size_t i = 0; i < matches_ids.size(); ++i) EXPECT_TRUE(info.IdCanConnect(matches_ids[i])); for (size_t i = 0; i < arraysize(nomatches_ids_array); ++i) @@ -217,7 +190,7 @@ TEST_F(ExternallyConnectableTest, IdCanConnect) { // all_ids = true. { - ExternallyConnectableInfo info(URLPatternSet(), matches_ids, true, false); + ExternallyConnectableInfo info(URLPatternSet(), matches_ids, true); for (size_t i = 0; i < matches_ids.size(); ++i) EXPECT_TRUE(info.IdCanConnect(matches_ids[i])); for (size_t i = 0; i < arraysize(nomatches_ids_array); ++i) diff --git a/chrome/renderer/chrome_mock_render_thread.cc b/chrome/renderer/chrome_mock_render_thread.cc index 94e2c10..c92cb39 100644 --- a/chrome/renderer/chrome_mock_render_thread.cc +++ b/chrome/renderer/chrome_mock_render_thread.cc @@ -78,7 +78,6 @@ void ChromeMockRenderThread::OnOpenChannelToExtension( int routing_id, const ExtensionMsg_ExternalConnectionInfo& info, const std::string& channel_name, - bool include_tls_channel_id, int* port_id) { *port_id = 0; } diff --git a/chrome/renderer/chrome_mock_render_thread.h b/chrome/renderer/chrome_mock_render_thread.h index 212d435..949e3ce 100644 --- a/chrome/renderer/chrome_mock_render_thread.h +++ b/chrome/renderer/chrome_mock_render_thread.h @@ -57,7 +57,6 @@ class ChromeMockRenderThread : public content::MockRenderThread { void OnOpenChannelToExtension(int routing_id, const ExtensionMsg_ExternalConnectionInfo& info, const std::string& channel_name, - bool include_tls_channel_id, int* port_id); #if defined(ENABLE_PRINTING) diff --git a/chrome/renderer/extensions/dispatcher.cc b/chrome/renderer/extensions/dispatcher.cc index 69411c2..e002ec7 100644 --- a/chrome/renderer/extensions/dispatcher.cc +++ b/chrome/renderer/extensions/dispatcher.cc @@ -529,13 +529,11 @@ void Dispatcher::OnDispatchOnConnect( int target_port_id, const std::string& channel_name, const base::DictionaryValue& source_tab, - const ExtensionMsg_ExternalConnectionInfo& info, - const std::string& tls_channel_id) { + const ExtensionMsg_ExternalConnectionInfo& info) { MessagingBindings::DispatchOnConnect( v8_context_set_.GetAll(), target_port_id, channel_name, source_tab, info.source_id, info.target_id, info.source_url, - tls_channel_id, NULL); // All render views. } diff --git a/chrome/renderer/extensions/dispatcher.h b/chrome/renderer/extensions/dispatcher.h index 7238c4d..99000ef 100644 --- a/chrome/renderer/extensions/dispatcher.h +++ b/chrome/renderer/extensions/dispatcher.h @@ -161,8 +161,7 @@ class Dispatcher : public content::RenderProcessObserver { void OnDispatchOnConnect(int target_port_id, const std::string& channel_name, const base::DictionaryValue& source_tab, - const ExtensionMsg_ExternalConnectionInfo& info, - const std::string& tls_channel_id); + const ExtensionMsg_ExternalConnectionInfo& info); void OnDeliverMessage(int target_port_id, const std::string& message); void OnDispatchOnDisconnect(int port_id, const std::string& error_message); void OnSetFunctionNames(const std::vector<std::string>& names); diff --git a/chrome/renderer/extensions/extension_helper.cc b/chrome/renderer/extensions/extension_helper.cc index 4eaf7a8..ea24317 100644 --- a/chrome/renderer/extensions/extension_helper.cc +++ b/chrome/renderer/extensions/extension_helper.cc @@ -271,13 +271,12 @@ void ExtensionHelper::OnExtensionDispatchOnConnect( int target_port_id, const std::string& channel_name, const base::DictionaryValue& source_tab, - const ExtensionMsg_ExternalConnectionInfo& info, - const std::string& tls_channel_id) { + const ExtensionMsg_ExternalConnectionInfo& info) { MessagingBindings::DispatchOnConnect( dispatcher_->v8_context_set().GetAll(), target_port_id, channel_name, source_tab, info.source_id, info.target_id, info.source_url, - tls_channel_id, render_view()); + render_view()); } void ExtensionHelper::OnExtensionDeliverMessage(int target_id, diff --git a/chrome/renderer/extensions/extension_helper.h b/chrome/renderer/extensions/extension_helper.h index 68ac896e..bc352be 100644 --- a/chrome/renderer/extensions/extension_helper.h +++ b/chrome/renderer/extensions/extension_helper.h @@ -84,8 +84,7 @@ class ExtensionHelper int target_port_id, const std::string& channel_name, const base::DictionaryValue& source_tab, - const ExtensionMsg_ExternalConnectionInfo& info, - const std::string& tls_channel_id); + const ExtensionMsg_ExternalConnectionInfo& info); void OnExtensionDeliverMessage(int target_port_id, const std::string& message); void OnExtensionDispatchOnDisconnect(int port_id, diff --git a/chrome/renderer/extensions/messaging_bindings.cc b/chrome/renderer/extensions/messaging_bindings.cc index efd46c9..153593c 100644 --- a/chrome/renderer/extensions/messaging_bindings.cc +++ b/chrome/renderer/extensions/messaging_bindings.cc @@ -240,7 +240,6 @@ void MessagingBindings::DispatchOnConnect( const std::string& source_extension_id, const std::string& target_extension_id, const GURL& source_url, - const std::string& tls_channel_id, content::RenderView* restrict_to_render_view) { v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); @@ -265,19 +264,13 @@ void MessagingBindings::DispatchOnConnect( if (!source_tab.empty()) tab = converter->ToV8Value(&source_tab, (*it)->v8_context()); - v8::Handle<v8::Value> tls_channel_id_value = v8::Undefined(); - if (tls_channel_id.size()) { - tls_channel_id_value = - v8::String::New(tls_channel_id.c_str(), tls_channel_id.size()); - } v8::Handle<v8::Value> arguments[] = { v8::Integer::New(target_port_id), v8::String::New(channel_name.c_str(), channel_name.size()), tab, v8::String::New(source_extension_id.c_str(), source_extension_id.size()), v8::String::New(target_extension_id.c_str(), target_extension_id.size()), - v8::String::New(source_url_spec.c_str(), source_url_spec.size()), - tls_channel_id_value + v8::String::New(source_url_spec.c_str(), source_url_spec.size()) }; v8::Handle<v8::Value> retval = (*it)->module_system()->CallModuleMethod( diff --git a/chrome/renderer/extensions/messaging_bindings.h b/chrome/renderer/extensions/messaging_bindings.h index 12e2096..811bc77 100644 --- a/chrome/renderer/extensions/messaging_bindings.h +++ b/chrome/renderer/extensions/messaging_bindings.h @@ -47,7 +47,6 @@ class MessagingBindings { const std::string& source_extension_id, const std::string& target_extension_id, const GURL& source_url, - const std::string& tls_channel_id, content::RenderView* restrict_to_render_view); // Delivers a message sent using content script messaging to some of the diff --git a/chrome/renderer/extensions/messaging_utils_unittest.cc b/chrome/renderer/extensions/messaging_utils_unittest.cc index 6e8f061..1163243 100644 --- a/chrome/renderer/extensions/messaging_utils_unittest.cc +++ b/chrome/renderer/extensions/messaging_utils_unittest.cc @@ -49,7 +49,7 @@ TEST_F(MessagingUtilsUnittest, ZeroArguments) { module_system_->Require("test"); } -TEST_F(MessagingUtilsUnittest, TooManyArgumentsNoOptions) { +TEST_F(MessagingUtilsUnittest, TooManyArguments) { ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); RegisterTestModule( "var args = messagingUtils.alignSendMessageArguments(\n" @@ -58,16 +58,7 @@ TEST_F(MessagingUtilsUnittest, TooManyArgumentsNoOptions) { module_system_->Require("test"); } -TEST_F(MessagingUtilsUnittest, TooManyArgumentsWithOptions) { - ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); - RegisterTestModule( - "var args = messagingUtils.alignSendMessageArguments(\n" - " ['a', 'b', 'c', 'd', 'e'], true);\n" - "AssertTrue(args === null);"); - module_system_->Require("test"); -} - -TEST_F(MessagingUtilsUnittest, FinalArgumentIsNotAFunctionNoOptions) { +TEST_F(MessagingUtilsUnittest, FinalArgumentIsNotAFunction) { ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); RegisterTestModule( "var args = messagingUtils.alignSendMessageArguments(\n" @@ -76,15 +67,6 @@ TEST_F(MessagingUtilsUnittest, FinalArgumentIsNotAFunctionNoOptions) { module_system_->Require("test"); } -TEST_F(MessagingUtilsUnittest, FinalArgumentIsNotAFunctionWithOptions) { - ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); - RegisterTestModule( - "var args = messagingUtils.alignSendMessageArguments(\n" - " ['a', 'b', 'c', 'd'], true);\n" - "AssertTrue(args === null);"); - module_system_->Require("test"); -} - TEST_F(MessagingUtilsUnittest, OneStringArgument) { ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); // Because the request argument is required, a single argument must get @@ -137,46 +119,5 @@ TEST_F(MessagingUtilsUnittest, OneStringAndOneFunctionArgument) { module_system_->Require("test"); } -TEST_F(MessagingUtilsUnittest, OneStringAndOneObjectArgument) { - ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); - // This tests an ambiguous set of arguments when options are present: - // chrome.runtime.sendMessage('target', {'msg': 'this is a message'}); - // vs. - // chrome.runtime.sendMessage('request', {'includeTlsChannelId': true}); - // - // The question is whether the string should map to the target and the - // dictionary to the message, or whether the string should map to the message - // and the dictionary to the options. Because the target and message arguments - // predate the options argument, we bind the string in this case to the - // targetId. - RegisterTestModule( - "var obj = {'b': true};\n" - "var args = messagingUtils.alignSendMessageArguments(['a', obj], true);\n" - "AssertTrue(args.length == 4);\n" - "AssertTrue(args[0] == 'a');\n" - "AssertTrue(args[1] == obj);\n" - "AssertTrue(args[2] === null);\n" - "AssertTrue(args[3] === null);"); - module_system_->Require("test"); -} - -TEST_F(MessagingUtilsUnittest, TwoObjectArguments) { - ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system_.get()); - // When two non-string arguments are provided and options are present, the - // two arguments must match request and options, respectively, because - // targetId must be a string. - RegisterTestModule( - "var obj1 = {'a': 'foo'};\n" - "var obj2 = {'b': 'bar'};\n" - "var args = messagingUtils.alignSendMessageArguments(\n" - " [obj1, obj2], true);\n" - "AssertTrue(args.length == 4);\n" - "AssertTrue(args[0] === null);\n" - "AssertTrue(args[1] == obj1);\n" - "AssertTrue(args[2] == obj2);\n" - "AssertTrue(args[3] === null);"); - module_system_->Require("test"); -} - } // namespace } // namespace extensions diff --git a/chrome/renderer/extensions/runtime_custom_bindings.cc b/chrome/renderer/extensions/runtime_custom_bindings.cc index e10423a..ea5f5bf 100644 --- a/chrome/renderer/extensions/runtime_custom_bindings.cc +++ b/chrome/renderer/extensions/runtime_custom_bindings.cc @@ -50,20 +50,17 @@ void RuntimeCustomBindings::OpenChannelToExtension( return; // The Javascript code should validate/fill the arguments. - CHECK_EQ(args.Length(), 3); - CHECK(args[0]->IsString() && args[1]->IsString() && args[2]->IsBoolean()); + CHECK_EQ(2, args.Length()); + CHECK(args[0]->IsString() && args[1]->IsString()); ExtensionMsg_ExternalConnectionInfo info; info.source_id = context()->GetExtensionID(); info.target_id = *v8::String::Utf8Value(args[0]->ToString()); info.source_url = context()->GetURL(); std::string channel_name = *v8::String::Utf8Value(args[1]->ToString()); - bool include_tls_channel_id = - args.Length() > 2 ? args[2]->BooleanValue() : false; int port_id = -1; renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( - renderview->GetRoutingID(), info, channel_name, include_tls_channel_id, - &port_id)); + renderview->GetRoutingID(), info, channel_name, &port_id)); args.GetReturnValue().Set(static_cast<int32_t>(port_id)); } diff --git a/chrome/renderer/resources/extensions/extension_custom_bindings.js b/chrome/renderer/resources/extensions/extension_custom_bindings.js index 08991485..84ab647 100644 --- a/chrome/renderer/resources/extensions/extension_custom_bindings.js +++ b/chrome/renderer/resources/extensions/extension_custom_bindings.js @@ -88,7 +88,7 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) { apiFunctions.setUpdateArgumentsPreValidate('sendRequest', $Function.bind(messaging.sendMessageUpdateArguments, - null, 'sendRequest', false /* hasOptionsArgument */)); + null, 'sendRequest')); apiFunctions.setHandleRequest('sendRequest', function(targetId, request, responseCallback) { diff --git a/chrome/renderer/resources/extensions/messaging.js b/chrome/renderer/resources/extensions/messaging.js index d3477ab..424ede1 100644 --- a/chrome/renderer/resources/extensions/messaging.js +++ b/chrome/renderer/resources/extensions/messaging.js @@ -213,8 +213,7 @@ sourceTab, sourceExtensionId, targetExtensionId, - sourceUrl, - tlsChannelId) { + sourceUrl) { // Only create a new Port if someone is actually listening for a connection. // In addition to being an optimization, this also fixes a bug where if 2 // channels were opened to and from the same process, closing one would @@ -237,8 +236,6 @@ sender.url = sourceUrl; if (sourceTab) sender.tab = sourceTab; - if (tlsChannelId) - sender.tlsChannelId = tlsChannelId; // Special case for sendRequest/onRequest and sendMessage/onMessage. if (channelName == kRequestChannel || channelName == kMessageChannel) { @@ -335,11 +332,9 @@ }); }; - function sendMessageUpdateArguments(functionName, hasOptionsArgument) { - // skip functionName and hasOptionsArgument - var args = $Array.slice(arguments, 2); - var alignedArgs = messagingUtils.alignSendMessageArguments(args, - hasOptionsArgument); + function sendMessageUpdateArguments(functionName) { + var args = $Array.slice(arguments, 1); // skip functionName + var alignedArgs = messagingUtils.alignSendMessageArguments(args); if (!alignedArgs) throw new Error('Invalid arguments to ' + functionName + '.'); return alignedArgs; diff --git a/chrome/renderer/resources/extensions/messaging_utils.js b/chrome/renderer/resources/extensions/messaging_utils.js index dd0fc28..64561b5 100644 --- a/chrome/renderer/resources/extensions/messaging_utils.js +++ b/chrome/renderer/resources/extensions/messaging_utils.js @@ -4,7 +4,7 @@ // Routines used to normalize arguments to messaging functions. -function alignSendMessageArguments(args, hasOptionsArgument) { +function alignSendMessageArguments(args) { // Align missing (optional) function arguments with the arguments that // schema validation is expecting, e.g. // extension.sendRequest(req) -> extension.sendRequest(null, req) @@ -15,26 +15,9 @@ function alignSendMessageArguments(args, hasOptionsArgument) { // responseCallback (last argument) is optional. var responseCallback = null; - if (typeof args[lastArg] == 'function') + if (typeof(args[lastArg]) == 'function') responseCallback = args[lastArg--]; - var options = null; - if (hasOptionsArgument && lastArg >= 1) { - // options (third argument) is optional. It can also be ambiguous which - // argument it should match. If there are more than two arguments remaining, - // options is definitely present: - if (lastArg > 1) { - options = args[lastArg--]; - } else { - // Exactly two arguments remaining. If the first argument is a string, - // it should bind to targetId, and the second argument should bind to - // request, which is required. In other words, when two arguments remain, - // only bind options when the first argument cannot bind to targetId. - if (!(args[0] === null || typeof args[0] == 'string')) - options = args[lastArg--]; - } - } - // request (second argument) is required. var request = args[lastArg--]; @@ -45,8 +28,6 @@ function alignSendMessageArguments(args, hasOptionsArgument) { if (lastArg != -1) return null; - if (hasOptionsArgument) - return [targetId, request, options, responseCallback]; return [targetId, request, responseCallback]; } diff --git a/chrome/renderer/resources/extensions/runtime_custom_bindings.js b/chrome/renderer/resources/extensions/runtime_custom_bindings.js index ae1fa95..04bf257 100644 --- a/chrome/renderer/resources/extensions/runtime_custom_bindings.js +++ b/chrome/renderer/resources/extensions/runtime_custom_bindings.js @@ -11,7 +11,6 @@ var messaging = require('messaging'); var runtimeNatives = requireNative('runtime'); var unloadEvent = require('unload_event'); var process = requireNative('process'); -var forEach = require('utils').forEach; var backgroundPage = window; var backgroundRequire = require; @@ -99,19 +98,14 @@ binding.registerCustomHook(function(binding, id, contextType) { var sendMessageUpdateArguments = messaging.sendMessageUpdateArguments; apiFunctions.setUpdateArgumentsPreValidate('sendMessage', - $Function.bind(sendMessageUpdateArguments, null, 'sendMessage', - true /* hasOptionsArgument */)); + $Function.bind(sendMessageUpdateArguments, null, 'sendMessage')); apiFunctions.setUpdateArgumentsPreValidate('sendNativeMessage', - $Function.bind(sendMessageUpdateArguments, null, 'sendNativeMessage', - false /* hasOptionsArgument */)); + $Function.bind(sendMessageUpdateArguments, null, 'sendNativeMessage')); apiFunctions.setHandleRequest('sendMessage', - function(targetId, message, options, responseCallback) { - var connectOptions = {name: messaging.kMessageChannel}; - forEach(options, function(k, v) { - connectOptions[k] = v; - }); - var port = runtime.connect(targetId || runtime.id, connectOptions); + function(targetId, message, responseCallback) { + var port = runtime.connect(targetId || runtime.id, + {name: messaging.kMessageChannel}); messaging.sendMessageImpl(port, message, responseCallback); }); @@ -164,11 +158,7 @@ binding.registerCustomHook(function(binding, id, contextType) { if (connectInfo && connectInfo.name) name = connectInfo.name; - var includeTlsChannelId = - !!(connectInfo && connectInfo.includeTlsChannelId); - - var portId = runtimeNatives.OpenChannelToExtension(targetId, name, - includeTlsChannelId); + var portId = runtimeNatives.OpenChannelToExtension(targetId, name); if (portId >= 0) return messaging.createPort(portId, name); }); diff --git a/chrome/test/data/extensions/api_test/messaging/externally_connectable/sites/assertions.js b/chrome/test/data/extensions/api_test/messaging/externally_connectable/sites/assertions.js index 0bcb3af7..4fd5275 100644 --- a/chrome/test/data/extensions/api_test/messaging/externally_connectable/sites/assertions.js +++ b/chrome/test/data/extensions/api_test/messaging/externally_connectable/sites/assertions.js @@ -70,8 +70,7 @@ var results = { COULD_NOT_ESTABLISH_CONNECTION_ERROR: 3, OTHER_ERROR: 4, INCORRECT_RESPONSE_SENDER: 5, - INCORRECT_RESPONSE_MESSAGE: 6, - NO_TLS_CHANNEL_ID: 7 + INCORRECT_RESPONSE_MESSAGE: 6 }; // Make the messages sent vaguely complex, but unambiguously JSON-ifiable. @@ -146,49 +145,6 @@ function sendToBrowser(msg) { domAutomationController.send(msg); } -function sendToBrowserForTlsChannelId(result) { - // Because the TLS channel ID tests read the TLS either an error code or the - // TLS channel ID string from the same value, they require the result code - // to be sent as a string. - // String() is clobbered, so coerce string creation with +. - sendToBrowser("" + result); -} - -function checkRuntime(reply) { - if (!reply) - reply = sendToBrowser; - - if (!chrome.runtime) { - reply(results.NAMESPACE_NOT_DEFINED); - return false; - } - - if (!chrome.runtime.connect || !chrome.runtime.sendMessage) { - reply(results.FUNCTION_NOT_DEFINED); - return false; - } - return true; -} - -function checkRuntimeForTlsChannelId() { - return checkRuntime(sendToBrowserForTlsChannelId); -} - -function checkTlsChannelIdResponse(response) { - if (chrome.runtime.lastError) { - if (chrome.runtime.lastError.message == kCouldNotEstablishConnection) - sendToBrowserForTlsChannelId( - results.COULD_NOT_ESTABLISH_CONNECTION_ERROR); - else - sendToBrowserForTlsChannelId(results.OTHER_ERROR); - return; - } - if (!response.sender.tlsChannelId) - sendToBrowserForTlsChannelId(results.NO_TLS_CHANNEL_ID); - else - sendToBrowserForTlsChannelId(response.sender.tlsChannelId); -} - window.actions = { appendIframe: function(src) { var iframe = document.createElement('iframe'); @@ -206,11 +162,15 @@ window.actions = { window.assertions = { canConnectAndSendMessages: function(extensionId, message) { - if (!checkRuntime()) + if (!chrome.runtime) { + sendToBrowser(results.NAMESPACE_NOT_DEFINED); return; + } - if (!message) - message = kMessage; + if (!chrome.runtime.sendMessage || !chrome.runtime.connect) { + sendToBrowser(results.FUNCTION_NOT_DEFINED); + return; + } if (!message) message = kMessage; @@ -260,33 +220,6 @@ window.assertions = { }); } sendToBrowser(result); - }, - - getTlsChannelIdFromPortConnect: function(extensionId, includeTlsChannelId, - message) { - if (!checkRuntimeForTlsChannelId()) - return; - - if (!message) - message = kMessage; - - var port = chrome.runtime.connect(extensionId, - {'includeTlsChannelId': includeTlsChannelId}); - port.onMessage.addListener(checkTlsChannelIdResponse); - port.postMessage(message); - }, - - getTlsChannelIdFromSendMessage: function(extensionId, includeTlsChannelId, - message) { - if (!checkRuntimeForTlsChannelId()) - return; - - if (!message) - message = kMessage; - - chrome.runtime.sendMessage(extensionId, message, - {'includeTlsChannelId': includeTlsChannelId}, - checkTlsChannelIdResponse); } }; diff --git a/chrome/test/data/extensions/manifest_tests/externally_connectable_matches_tls_channel_id.json b/chrome/test/data/extensions/manifest_tests/externally_connectable_matches_tls_channel_id.json deleted file mode 100644 index c6f0db9..0000000 --- a/chrome/test/data/extensions/manifest_tests/externally_connectable_matches_tls_channel_id.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "unit_tests --gtest_filter=ExternallyConnectableTest.MatchesWithTlsChannelId", - "version": "1", - "manifest_version": 2, - "externally_connectable": { - "matches": [ - "http://example.com/", - "*://*.google.com/*", - "http://build.chromium.org/*" - ], - "accepts_tls_channel_id": true - } -} |