diff --git a/chromium_src/ios/web/public/web_state.h b/chromium_src/ios/web/public/web_state.h index 28099208d443..82b7b4de1f7c 100644 --- a/chromium_src/ios/web/public/web_state.h +++ b/chromium_src/ios/web/public/web_state.h @@ -1,31 +1,23 @@ -#define callbacks_ \ - callbacks_; \ - \ - public: \ - template \ - void AddUntrustedInterface( \ - std::string_view interface_name, \ - base::RepeatingCallback)> \ - callback) { \ - if (auto it = untrusted_callbacks_.find(std::string(interface_name)); \ - it != untrusted_callbacks_.end()) { \ - it->second.emplace( \ - base::BindRepeating(&WrapCallback, std::move(callback))); \ - } else { \ - untrusted_callbacks_.emplace( \ - std::string(interface_name), \ - {base::BindRepeating(&WrapCallback, \ - std::move(callback))}); \ - } \ - } \ - bool GetUntrustedInterfaces(std::string_view interface_name) const { \ - return untrusted_callbacks_.find(std::string(interface_name)) != \ - untrusted_callbacks_.end(); \ - } \ - \ - private: \ - std::map> untrusted_callbacks_ +#define callbacks_ \ + callbacks_; \ + \ + public: \ + template \ + void AddUntrustedInterface( \ + const GURL& url, \ + base::RepeatingCallback)> \ + callback) { \ + CHECK(!url.is_empty()); \ + untrusted_callbacks_[url].emplace( \ + std::string(Interface::Name_), \ + base::BindRepeating(&WrapCallback, std::move(callback))); \ + } \ + void BindUntrustedInterface(const GURL& url, \ + mojo::GenericPendingReceiver receiver); \ + \ + private: \ + std::map> untrusted_callbacks_ #include "src/ios/web/public/web_state.h" diff --git a/chromium_src/ios/web/web_state/web_state.mm b/chromium_src/ios/web/web_state/web_state.mm new file mode 100644 index 000000000000..1848e67e859a --- /dev/null +++ b/chromium_src/ios/web/web_state/web_state.mm @@ -0,0 +1,17 @@ + +#include "src/ios/web/web_state/web_state.mm" + +namespace web { +void WebState::InterfaceBinder::BindUntrustedInterface(const GURL& url, mojo::GenericPendingReceiver receiver) { + DCHECK(!url.is_empty()); + DCHECK(receiver.is_valid()); + if (auto it = untrusted_callbacks_.find(url); it != untrusted_callbacks_.end()) { + if (auto jt = it->second.find(*receiver.interface_name()); jt != it->second.end()) { + jt->second.Run(&receiver); + + GetWebClient()->BindInterfaceReceiverFromMainFrame(web_state_, + std::move(receiver)); + } + } +} +} // namespace web