1 // Copyright 2020 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 WEBLAYER_BROWSER_URL_BAR_URL_BAR_CONTROLLER_IMPL_H_
6 #define WEBLAYER_BROWSER_URL_BAR_URL_BAR_CONTROLLER_IMPL_H_
7 
8 #include "base/strings/string16.h"
9 #include "build/build_config.h"
10 #include "components/omnibox/browser/location_bar_model_delegate.h"
11 #include "components/omnibox/browser/location_bar_model_impl.h"
12 #include "weblayer/public/url_bar_controller.h"
13 
14 #if defined(OS_ANDROID)
15 #include "base/android/scoped_java_ref.h"
16 #endif
17 
18 namespace content {
19 class WebContents;
20 }
21 
22 namespace weblayer {
23 class BrowserImpl;
24 
25 class UrlBarControllerImpl : public UrlBarController,
26                              public LocationBarModelDelegate {
27  public:
28   explicit UrlBarControllerImpl(BrowserImpl* native_browser);
29   ~UrlBarControllerImpl() override;
30   UrlBarControllerImpl(const UrlBarControllerImpl&) = delete;
31   UrlBarControllerImpl& operator=(const UrlBarControllerImpl&) = delete;
32 
33 #if defined(OS_ANDROID)
34   base::android::ScopedJavaLocalRef<jstring> GetUrlForDisplay(JNIEnv* env);
35   jint GetConnectionSecurityLevel(JNIEnv* env);
36   jboolean ShouldShowDangerTriangleForWarningLevel(JNIEnv* env);
37 #endif
38 
39   // UrlBarController:
40   base::string16 GetUrlForDisplay() override;
41   security_state::SecurityLevel GetConnectionSecurityLevel() override;
42   bool ShouldShowDangerTriangleForWarningLevel() override;
43 
44   // LocationBarModelDelegate:
45   bool GetURL(GURL* url) const override;
46   bool ShouldTrimDisplayUrlAfterHostName() const override;
47   base::string16 FormattedStringWithEquivalentMeaning(
48       const GURL& url,
49       const base::string16& formatted_url) const override;
50 
51  private:
52   content::WebContents* GetActiveWebContents() const;
53   BrowserImpl* const browser_;
54   std::unique_ptr<LocationBarModelImpl> location_bar_model_;
55 };
56 
57 }  // namespace weblayer
58 
59 #endif  // WEBLAYER_BROWSER_URL_BAR_URL_BAR_CONTROLLER_IMPL_H_
60