Exemple #1
0
static void testLoadFailedWithTLSErrors(TLSErrorsTest* test, gconstpointer)
{
    WebKitWebContext* context = webkit_web_view_get_context(test->m_webView);
    WebKitTLSErrorsPolicy originalPolicy = webkit_web_context_get_tls_errors_policy(context);
    webkit_web_context_set_tls_errors_policy(context, WEBKIT_TLS_ERRORS_POLICY_FAIL);

    // The load-failed-with-tls-errors signal should be emitted when there is a TLS failure.
    test->loadURI(kHttpsServer->getURIForPath("/test-tls/").data());
    test->waitUntilLoadFinished();
    g_assert(G_IS_TLS_CERTIFICATE(test->certificate()));
    g_assert_cmpuint(test->tlsErrors(), ==, G_TLS_CERTIFICATE_UNKNOWN_CA);
    g_assert_cmpstr(test->host(), ==, soup_uri_get_host(kHttpsServer->baseURI()));
    g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted);
    g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::LoadFailedWithTLSErrors);
    g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished);

    // Test allowing an exception for this certificate on this host.
    webkit_web_context_allow_tls_certificate_for_host(context, test->certificate(), test->host());
    // The page should now load without errors.
    test->loadURI(kHttpsServer->getURIForPath("/test-tls/").data());
    test->waitUntilLoadFinished();

    g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted);
    g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::LoadCommitted);
    g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished);
    g_assert_cmpstr(webkit_web_view_get_title(test->m_webView), ==, TLSExpectedSuccessTitle);

    webkit_web_context_set_tls_errors_policy(context, originalPolicy);
}
Exemple #2
0
static void testTLSErrorsRedirect(SSLTest* test, gconstpointer)
{
    WebKitWebContext* context = webkit_web_view_get_context(test->m_webView);
    WebKitTLSErrorsPolicy originalPolicy = webkit_web_context_get_tls_errors_policy(context);
    webkit_web_context_set_tls_errors_policy(context, WEBKIT_TLS_ERRORS_POLICY_FAIL);

    test->loadURI(kHttpsServer->getURIForPath("/redirect").data());
    test->waitUntilLoadFinished();
    g_assert(test->m_loadFailed);
    g_assert(test->m_loadEvents.contains(LoadTrackingTest::ProvisionalLoadFailed));
    g_assert(!test->m_loadEvents.contains(LoadTrackingTest::LoadCommitted));

    webkit_web_context_set_tls_errors_policy(context, originalPolicy);
}
Exemple #3
0
static void testInsecureContent(InsecureContentTest* test, gconstpointer)
{
    WebKitWebContext* context = webkit_web_view_get_context(test->m_webView);
    WebKitTLSErrorsPolicy originalPolicy = webkit_web_context_get_tls_errors_policy(context);
    webkit_web_context_set_tls_errors_policy(context, WEBKIT_TLS_ERRORS_POLICY_IGNORE);

    test->loadURI(kHttpsServer->getURIForPath("/insecure-content/").data());
    test->waitUntilLoadFinished();

    g_assert(test->m_insecureContentRun);
    g_assert(test->m_insecureContentDisplayed);

    webkit_web_context_set_tls_errors_policy(context, originalPolicy);
}
Exemple #4
0
static int tls_policy(Client *c, const char *name, DataType type, void *value, void *data)
{
    gboolean strict = *((gboolean*)value);

    webkit_web_context_set_tls_errors_policy(
        webkit_web_context_get_default(),
        strict ? WEBKIT_TLS_ERRORS_POLICY_FAIL : WEBKIT_TLS_ERRORS_POLICY_IGNORE);

    return CMD_SUCCESS;
}
Exemple #5
0
static void testSSL(SSLTest* test, gconstpointer)
{
    WebKitWebContext* context = webkit_web_view_get_context(test->m_webView);
    WebKitTLSErrorsPolicy originalPolicy = webkit_web_context_get_tls_errors_policy(context);
    webkit_web_context_set_tls_errors_policy(context, WEBKIT_TLS_ERRORS_POLICY_IGNORE);

    test->loadURI(kHttpsServer->getURIForPath("/").data());
    test->waitUntilLoadFinished();
    g_assert(test->m_certificate);
    // We always expect errors because we are using a self-signed certificate,
    // but only G_TLS_CERTIFICATE_UNKNOWN_CA flags should be present.
    g_assert(test->m_tlsErrors);
    g_assert_cmpuint(test->m_tlsErrors, ==, G_TLS_CERTIFICATE_UNKNOWN_CA);

    // Non HTTPS loads shouldn't have a certificate nor errors.
    test->loadHtml(indexHTML, 0);
    test->waitUntilLoadFinished();
    g_assert(!test->m_certificate);
    g_assert(!test->m_tlsErrors);

    webkit_web_context_set_tls_errors_policy(context, originalPolicy);
}
Exemple #6
0
static void testTLSErrorsPolicy(SSLTest* test, gconstpointer)
{
    WebKitWebContext* context = webkit_web_view_get_context(test->m_webView);
    // TLS errors are treated as transport failures by default.
    g_assert(webkit_web_context_get_tls_errors_policy(context) == WEBKIT_TLS_ERRORS_POLICY_FAIL);
    test->loadURI(kHttpsServer->getURIForPath("/").data());
    test->waitUntilLoadFinished();
    g_assert(test->m_loadFailed);
    g_assert(test->m_loadEvents.contains(LoadTrackingTest::ProvisionalLoadFailed));
    g_assert(!test->m_loadEvents.contains(LoadTrackingTest::LoadCommitted));

    webkit_web_context_set_tls_errors_policy(context, WEBKIT_TLS_ERRORS_POLICY_IGNORE);
    g_assert(webkit_web_context_get_tls_errors_policy(context) == WEBKIT_TLS_ERRORS_POLICY_IGNORE);

    test->m_loadFailed = false;
    test->loadURI(kHttpsServer->getURIForPath("/").data());
    test->waitUntilLoadFinished();
    g_assert(!test->m_loadFailed);

    webkit_web_context_set_tls_errors_policy(context, WEBKIT_TLS_ERRORS_POLICY_FAIL);
    g_assert(webkit_web_context_get_tls_errors_policy(context) == WEBKIT_TLS_ERRORS_POLICY_FAIL);
}
Exemple #7
0
int main(int argn, char **argv)
{
    config = config_init(argn, argv);

	gtk_init(0, NULL);
    //GtkWidget * window = gtk_offscreen_window_new();
    GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 900, 600);
    GdkScreen* screen = gtk_window_get_screen(GTK_WINDOW(window));
    GdkVisual* rgba_visual = gdk_screen_get_rgba_visual(screen);
    WebKitSettings * setting;
    WebKitWebView *webView;
    if (rgba_visual) {
        gtk_widget_set_visual(window, rgba_visual);
    }
    gtk_widget_set_app_paintable(window, TRUE);

	WebKitWebContext* context = webkit_web_context_get_default();
	//webkit_web_context_set_process_model(context, WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
	//webkit_web_context_set_process_model(context, WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS);
	//webkit_web_context_set_cache_model(context, WEBKIT_CACHE_MODEL_WEB_BROWSER);
    webkit_web_context_set_disk_cache_directory(context, "/tmp/cache");
    webkit_web_context_set_process_model(context, WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
	webkit_web_context_set_cache_model(context, WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
	webkit_web_context_set_tls_errors_policy(context, WEBKIT_TLS_ERRORS_POLICY_IGNORE);

    webkit_web_context_clear_cache(context);

	webView = WEBKIT_WEB_VIEW(
            webkit_web_view_new_with_user_content_manager(webkit_user_content_manager_new()));
    //webView =WEBKIT_WEB_VIEW(webkit_web_view_new_with_context(context));
    setting = webkit_web_view_get_settings(webView);
    webkit_settings_set_enable_page_cache(setting, false);
    webkit_settings_set_enable_javascript(setting, true);
    webkit_settings_set_enable_offline_web_application_cache(setting, false);
	//webView = WEBKIT_WEB_VIEW(webkit_web_view_new_with_settings(setting));
    g_object_set(setting,
	//	"enable-private-browsing", NanBooleanOptionValue(opts, H("private"), false),
		"enable-plugins", FALSE,
		"print-backgrounds", TRUE,
		"enable-javascript", TRUE,
		"enable-html5-database", FALSE,
		"enable-html5-local-storage", FALSE,
		"enable-java", FALSE,
		"enable-page-cache", FALSE,
		"enable-write-console-messages-to-stdout", TRUE,
		"enable-offline-web-application-cache", FALSE,
	//	"auto-load-images", NanBooleanOptionValue(opts, H("images"), true),
		"zoom-text-only", FALSE,
		"media-playback-requires-user-gesture", FALSE, // effectively disables media playback ?
	//	"user-agent", ua,
        NULL
	);

	gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(webView));
	g_signal_connect(webView, "ready-to-show", G_CALLBACK(ready_to_show), NULL);
	g_signal_connect(webView, "load-changed", G_CALLBACK(web_view_load_changed), NULL);
	g_signal_connect(webView, "web-view-ready", G_CALLBACK(ready_to_show), NULL);

    g_signal_connect(webView, "resource-load-started", G_CALLBACK(resource_started), window);

    g_signal_connect(window, "destroy", G_CALLBACK(destroyWindowCb), NULL);
    g_signal_connect(webView, "close-web-view", G_CALLBACK(closeWebViewCb), window);

    webkit_web_view_load_uri(webView, config->url);
	//gtk_widget_show_all(window);

    gtk_main();

    return 0;
}
static void
ephy_embed_shell_startup (GApplication* application)
{
  EphyEmbedShell *shell = EPHY_EMBED_SHELL (application);
  EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
  char *favicon_db_path;
  WebKitCookieManager *cookie_manager;
  char *filename;
  char *cookie_policy;

  G_APPLICATION_CLASS (ephy_embed_shell_parent_class)->startup (application);

  /* We're not remoting, setup the Web Context if we are not running in a test.
     Tests already do this after construction. */
  if (priv->mode != EPHY_EMBED_SHELL_MODE_TEST)
    ephy_embed_shell_create_web_context (embed_shell);

  ephy_embed_shell_setup_web_extensions_connection (shell);

  /* User content manager */
  if (priv->mode != EPHY_EMBED_SHELL_MODE_TEST)
    priv->user_content = webkit_user_content_manager_new ();

  webkit_user_content_manager_register_script_message_handler (priv->user_content,
                                                               "overview");
  g_signal_connect (priv->user_content, "script-message-received::overview",
                    G_CALLBACK (web_extension_overview_message_received_cb),
                    shell);

  webkit_user_content_manager_register_script_message_handler (priv->user_content,
                                                               "tlsErrorPage");
  g_signal_connect (priv->user_content, "script-message-received::tlsErrorPage",
                    G_CALLBACK (web_extension_tls_error_page_message_received_cb),
                    shell);

  webkit_user_content_manager_register_script_message_handler (priv->user_content,
                                                               "formAuthData");
  g_signal_connect (priv->user_content, "script-message-received::formAuthData",
                    G_CALLBACK (web_extension_form_auth_data_message_received_cb),
                    shell);

  webkit_user_content_manager_register_script_message_handler (priv->user_content,
                                                               "aboutApps");
  g_signal_connect (priv->user_content, "script-message-received::aboutApps",
                    G_CALLBACK (web_extension_about_apps_message_received_cb),
                    shell);

  ephy_embed_shell_setup_process_model (shell);
  g_signal_connect (priv->web_context, "initialize-web-extensions",
                    G_CALLBACK (initialize_web_extensions),
                    shell);

  /* Favicon Database */
  favicon_db_path = g_build_filename (EPHY_EMBED_SHELL_MODE_HAS_PRIVATE_PROFILE (priv->mode) ?
                                      ephy_dot_dir () : g_get_user_cache_dir (),
                                      "icondatabase", NULL);
  webkit_web_context_set_favicon_database_directory (priv->web_context, favicon_db_path);
  g_free (favicon_db_path);

  /* Do not ignore TLS errors. */
  webkit_web_context_set_tls_errors_policy (priv->web_context, WEBKIT_TLS_ERRORS_POLICY_FAIL);


  /* about: URIs handler */
  priv->about_handler = ephy_about_handler_new ();
  webkit_web_context_register_uri_scheme (priv->web_context,
                                          EPHY_ABOUT_SCHEME,
                                          (WebKitURISchemeRequestCallback)about_request_cb,
                                          shell, NULL);

  /* Register about scheme as local so that it can contain file resources */
  webkit_security_manager_register_uri_scheme_as_local (webkit_web_context_get_security_manager (priv->web_context),
                                                        EPHY_ABOUT_SCHEME);

  /* ephy-resource handler */
  webkit_web_context_register_uri_scheme (priv->web_context, "ephy-resource",
                                          (WebKitURISchemeRequestCallback)ephy_resource_request_cb,
                                          NULL, NULL);

  /* Store cookies in moz-compatible SQLite format */
  cookie_manager = webkit_web_context_get_cookie_manager (priv->web_context);
  filename = g_build_filename (ephy_dot_dir (), "cookies.sqlite", NULL);
  webkit_cookie_manager_set_persistent_storage (cookie_manager, filename,
                                                WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE);
  g_free (filename);

  cookie_policy = g_settings_get_string (EPHY_SETTINGS_WEB,
                                         EPHY_PREFS_WEB_COOKIES_POLICY);
  ephy_embed_prefs_set_cookie_accept_policy (cookie_manager, cookie_policy);
  g_free (cookie_policy);
}
Exemple #9
0
int main(int argc, char *argv[])
{
    gtk_init(&argc, &argv);
    g_setenv("WEBKIT_INJECTED_BUNDLE_PATH", WEBKIT_INJECTED_BUNDLE_PATH, FALSE);

    const gchar *multiprocess = g_getenv("MINIBROWSER_MULTIPROCESS");
    if(true){//wangc force multiprocess : (multiprocess && *multiprocess) {
        webkit_web_context_set_process_model(webkit_web_context_get_default(),
            WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
    }

    GOptionContext *context = g_option_context_new(NULL);
    g_option_context_add_main_entries(context, commandLineOptions, 0);
    g_option_context_add_group(context, gtk_get_option_group(TRUE));

    WebKitSettings *webkitSettings = webkit_settings_new();
    InitSettingsWithFile(webkitSettings);  //Init WebKitSettings With Config File.
    webkit_settings_set_enable_developer_extras(webkitSettings, TRUE);
    webkit_settings_set_enable_webgl(webkitSettings, TRUE);
    if (!addSettingsGroupToContext(context, webkitSettings))
        g_clear_object(&webkitSettings);

    GError *error = 0;
    if (!g_option_context_parse(context, &argc, &argv, &error)) {
        g_printerr("Cannot parse arguments: %s\n", error->message);
        g_error_free(error);
        g_option_context_free(context);

        return 1;
    }
    g_option_context_free (context);

    g_assert(initCookieManager(webkitSettings));

    // Enable the favicon database, by specifying the default directory.
    webkit_web_context_set_favicon_database_directory(webkit_web_context_get_default(), NULL);

    webkit_web_context_register_uri_scheme(webkit_web_context_get_default(), miniBrowserAboutScheme, aboutURISchemeRequestCallback, NULL, NULL);

    webkit_web_context_set_tls_errors_policy(webkit_web_context_get_default(), WEBKIT_TLS_ERRORS_POLICY_IGNORE);

    if (uriArguments) {
        int i;

        for (i = 0; uriArguments[i]; i++)
            createBrowserWindow(uriArguments[i], webkitSettings);
    } else { 
        //createBrowserWindow("http://www.baidu.com/", webkitSettings);
        //createBrowserWindow("/home/zgh/CuprumBrowser/WebKitBrowser/WebKitBuild/Release/bin/resources/index.html",NULL);
        gchar indexpage[BUFSIZE] = {0};
        gchar *uri;
        gchar *strval;
        int ivalue;
        g_object_get(webkitSettings,
                 key[PROP_ON_STARTUP], &ivalue,
                 NULL);

        //default url:::  http://nfs-cloud.cn:81/appCenter/open/softcenter
        /*Depending on_startup radiobutton to loading corresponding url. sunhaiming add */
        switch (ivalue) {
        case 0:
            strcat(indexpage, get_cuprum_dir());
            strcat(indexpage, "/resources/assets/newtab.html");
            printf("%s\n", indexpage);
            uri = indexpage;
            break;
        case 1:
            uri = "http://nfs-cloud.cn:81/appCenter/open/softcenter";
            break;
        case 2:  
            g_object_get(webkitSettings,
                     key[PROP_HOME_PAGE], &strval,
                     NULL);
            if (!g_strcmp0(strval, "")) {
                uri = "http://nfs-cloud.cn:81/appCenter/open/softcenter";
            } else {
                uri = strval;
            }
            break;
        default:
            printf("error, read PROP_ON_STARTUP  ivalue = %i\n", ivalue);
            break;
        }
        createBrowserWindow(uri, webkitSettings);
    }

    g_clear_object(&webkitSettings);

    gtk_main();

    return 0;
}