forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A refacotring in the renderer side: introduce InjectionHost to de-cou…
…ple extensions and to support content script injection out of chrome extensions. BUG=437566 Review URL: https://codereview.chromium.org/885493007 Cr-Commit-Position: refs/heads/master@{#316283}
- Loading branch information
hanxi
authored and
Commit bot
committed
Feb 13, 2015
1 parent
a3d8170
commit a5c856c
Showing
18 changed files
with
318 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2015 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 "extensions/common/host_id.h" | ||
|
||
HostID::HostID() { | ||
} | ||
|
||
HostID::HostID(HostType type, const std::string& id) | ||
: type_(type), id_(id) { | ||
} | ||
|
||
HostID::HostID(const HostID& host_id) | ||
: type_(host_id.type()), | ||
id_(host_id.id()) { | ||
} | ||
|
||
HostID::~HostID() { | ||
} | ||
|
||
bool HostID::operator<(const HostID& host_id) const { | ||
if (type_ != host_id.type()) | ||
return type_ < host_id.type(); | ||
else if (id_ != host_id.id()) | ||
return id_ < host_id.id(); | ||
return false; | ||
} | ||
|
||
bool HostID::operator==(const HostID& host_id) const { | ||
return type_ == host_id.type() && id_ == host_id.id(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2015 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 "extensions/common/manifest_handlers/csp_info.h" | ||
#include "extensions/renderer/extension_injection_host.h" | ||
|
||
namespace extensions { | ||
|
||
ExtensionInjectionHost::ExtensionInjectionHost( | ||
const scoped_refptr<const Extension>& extension) | ||
: InjectionHost(HostID(HostID::EXTENSIONS, extension->id())), | ||
extension_(extension) { | ||
} | ||
|
||
ExtensionInjectionHost::~ExtensionInjectionHost() { | ||
} | ||
|
||
const std::string& ExtensionInjectionHost::GetContentSecurityPolicy() const { | ||
return CSPInfo::GetContentSecurityPolicy(extension_.get()); | ||
} | ||
|
||
const GURL& ExtensionInjectionHost::url() const { | ||
return extension_->url(); | ||
} | ||
|
||
const std::string& ExtensionInjectionHost::name() const { | ||
return extension_->name(); | ||
} | ||
|
||
PermissionsData::AccessType ExtensionInjectionHost::CanExecuteOnFrame( | ||
const GURL& document_url, | ||
const GURL& top_frame_url, | ||
int tab_id, | ||
bool is_declarative) const { | ||
// Declarative user scripts use "page access" (from "permissions" section in | ||
// manifest) whereas non-declarative user scripts use custom | ||
// "content script access" logic. | ||
if (is_declarative) { | ||
return extension_->permissions_data()->GetPageAccess( | ||
extension_.get(), | ||
document_url, | ||
top_frame_url, | ||
tab_id, | ||
-1, // no process id | ||
nullptr /* ignore error */); | ||
} else { | ||
return extension_->permissions_data()->GetContentScriptAccess( | ||
extension_.get(), | ||
document_url, | ||
top_frame_url, | ||
tab_id, | ||
-1, // no process id | ||
nullptr /* ignore error */); | ||
} | ||
} | ||
|
||
} // namespace extensions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2015 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 EXTENSIONS_RENDERER_EXTENSION_INJECTION_HOST_H_ | ||
#define EXTENSIONS_RENDERER_EXTENSION_INJECTION_HOST_H_ | ||
|
||
#include "base/memory/ref_counted.h" | ||
#include "extensions/common/extension.h" | ||
#include "extensions/renderer/injection_host.h" | ||
|
||
namespace extensions { | ||
|
||
// A wrapper class that holds an extension and implements the InjectionHost | ||
// interface. | ||
class ExtensionInjectionHost : public InjectionHost { | ||
public: | ||
ExtensionInjectionHost(const scoped_refptr<const Extension>& extension); | ||
~ExtensionInjectionHost() override; | ||
|
||
private: | ||
// InjectionHost: | ||
const std::string& GetContentSecurityPolicy() const override; | ||
const GURL& url() const override; | ||
const std::string& name() const override; | ||
PermissionsData::AccessType CanExecuteOnFrame( | ||
const GURL& document_url, | ||
const GURL& top_frame_url, | ||
int tab_id, | ||
bool is_declarative) const override; | ||
|
||
scoped_refptr<const Extension> extension_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(ExtensionInjectionHost); | ||
}; | ||
|
||
} // namespace extesions | ||
|
||
#endif // EXTENSIONS_RENDERER_EXTENSION_INJECTION_HOST_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2015 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 "extensions/renderer/injection_host.h" | ||
|
||
InjectionHost::InjectionHost(const HostID& host_id) : | ||
id_(host_id) { | ||
} | ||
|
||
InjectionHost::~InjectionHost() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2015 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 EXTENSIONS_RENDERER_INJECTION_HOST_H | ||
#define EXTENSIONS_RENDERER_INJECTION_HOST_H | ||
|
||
#include "extensions/common/host_id.h" | ||
#include "extensions/common/permissions/permissions_data.h" | ||
#include "url/gurl.h" | ||
|
||
// An interface for all kinds of hosts who own user scripts. | ||
class InjectionHost { | ||
public: | ||
InjectionHost(const HostID& host_id); | ||
virtual ~InjectionHost(); | ||
|
||
virtual const std::string& GetContentSecurityPolicy() const = 0; | ||
|
||
// The base url for the host. | ||
virtual const GURL& url() const = 0; | ||
|
||
// The human-readable name of the host. | ||
virtual const std::string& name() const = 0; | ||
|
||
// Returns true if the script should execute. | ||
virtual extensions::PermissionsData::AccessType CanExecuteOnFrame( | ||
const GURL& document_url, | ||
const GURL& top_frame_url, | ||
int tab_id, | ||
bool is_declarative) const = 0; | ||
|
||
const HostID& id() const { return id_; } | ||
private: | ||
// The ID of the host. | ||
HostID id_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(InjectionHost); | ||
}; | ||
|
||
#endif // EXTENSIONS_RENDERER_INJECTION_HOST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.