OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef IOS_WEB_VIEW_INTERNAL_WEB_VIEW_EARLY_PAGE_SCRIPT_PROVIDER_H_ |
| 6 #define IOS_WEB_VIEW_INTERNAL_WEB_VIEW_EARLY_PAGE_SCRIPT_PROVIDER_H_ |
| 7 |
| 8 #include <Foundation/Foundation.h> |
| 9 |
| 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/supports_user_data.h" |
| 13 |
| 14 namespace web { |
| 15 class BrowserState; |
| 16 } |
| 17 |
| 18 namespace ios_web_view { |
| 19 |
| 20 // A provider class associated with a single web::BrowserState object. Keeps |
| 21 // an early page script, a JavaScript injected into all pages as early as |
| 22 // possible. |
| 23 // |
| 24 // Not threadsafe. Must be used only on the main thread. |
| 25 class WebViewEarlyPageScriptProvider : public base::SupportsUserData::Data { |
| 26 public: |
| 27 ~WebViewEarlyPageScriptProvider() override; |
| 28 |
| 29 // Returns a provider for the given |browser_state|. Lazily attaches one if it |
| 30 // does not exist. |browser_state| can not be null. |
| 31 static WebViewEarlyPageScriptProvider& FromBrowserState( |
| 32 web::BrowserState* _Nonnull browser_state); |
| 33 |
| 34 // Getter and Setter for the JavaScript source code. |
| 35 NSString* _Nonnull GetScript() { return script_.get(); } |
| 36 void SetScript(NSString* _Nonnull script); |
| 37 |
| 38 private: |
| 39 WebViewEarlyPageScriptProvider(); |
| 40 |
| 41 // The JavaScript source code. |
| 42 base::scoped_nsobject<NSString> script_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(WebViewEarlyPageScriptProvider); |
| 45 }; |
| 46 |
| 47 } // namespace ios_web_view |
| 48 |
| 49 #endif // IOS_WEB_VIEW_INTERNAL_WEB_VIEW_EARLY_PAGE_SCRIPT_PROVIDER_H_ |
OLD | NEW |